why so hateful java? ;_;

Apr 22, 2009 04:42

Homework is eating my brain, and it's the dumbest thing. I've got the whole program running, except for getting it to error trap for blank spaces/multiple words (the user is supposed to enter a single word). The closest I've been able to get is ( Read more... )

techno geekery, random

Leave a comment

Comments 2

lysryu April 22 2009, 13:12:08 UTC
Ugh Java. It was interesting enough when I did it in first year as an elective unit but I wouldn't want to continue on with it into the higher level units - coding isn't really my thing. Yeah like you mentioned - sooo annoying when it seems like you've got everything else coded but a small bit of code is preventing everything else from working.

Reply


anonymous April 22 2009, 18:18:28 UTC
I don't know how you fetch the input from the user, but it might be the fetch of the word that is wrong, could it not?

This works just perfectly for me

import java.io.*;
public class Test {

public static void main(String[] args) {

BufferedReader Keyboard = new BufferedReader(new InputStreamReader(System.in));
String a = "";
System.out.println("Write a word: ");
try{
a = Keyboard.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
System.out.println(a);
while(a.contains(" ")){

System.out.println("Write one word only: ");
try{
a = Keyboard.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
}
System.out.println("You wrote: " + a);
}
}

Reply


Leave a comment

Up