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... )
Comments 2
Reply
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