- Apr 25, 2004
- 6,656
- 737
- 126
Easy, I know, but I don't have any programming experience so to speak of, and I've been thrown into a java class...
Could someone tell me the command for a user input? The program prompts different things then places them into a poem. I already have it written, but when I run it it doesn't prompt, rather it just places null because the user never inputted...
Code looks like this:
public class Poem1 {
public static void main(String[] args) {
Scanner scr = new Scanner(System.in) ;
System.out.println ("What is your name?") ;
String name = scr.nextLine() ;
System.out.println ("What is something red?") ;
String red = scr.nextLine() ;
System.out.println ("What is something blue?") ;
String blue = scr.nextLine() ;
System.out.println ("What is something sweet?") ;
String sweet = scr.nextLine() ;
System.out.println ("What else is sweet?") ;
String sweet2 = scr.nextLine() ;
System.out.println (red + " are red,") ;
System.out.println (" " + blue + " are blue,") ;
System.out.println (" " + sweet + " and " + sweet2 + " are sweet,") ;
System.out.println (" And so are you, " + name) ;
}
}
I probably don't need the scanner, but I'm using it as a template because we worked on it in class the other day.
Could someone tell me the command for a user input? The program prompts different things then places them into a poem. I already have it written, but when I run it it doesn't prompt, rather it just places null because the user never inputted...
Code looks like this:
public class Poem1 {
public static void main(String[] args) {
Scanner scr = new Scanner(System.in) ;
System.out.println ("What is your name?") ;
String name = scr.nextLine() ;
System.out.println ("What is something red?") ;
String red = scr.nextLine() ;
System.out.println ("What is something blue?") ;
String blue = scr.nextLine() ;
System.out.println ("What is something sweet?") ;
String sweet = scr.nextLine() ;
System.out.println ("What else is sweet?") ;
String sweet2 = scr.nextLine() ;
System.out.println (red + " are red,") ;
System.out.println (" " + blue + " are blue,") ;
System.out.println (" " + sweet + " and " + sweet2 + " are sweet,") ;
System.out.println (" And so are you, " + name) ;
}
}
I probably don't need the scanner, but I'm using it as a template because we worked on it in class the other day.