-
Simple Java question
Hey guys, I'm new to the forums, just got a question from my online professor, but I can't seem to get the problem right.
The problem is to write a code that allows the user to put in a line of text, and then get that line of text back in UPPER case and lower case.
My code is as follows
import java.util.Scanner;
public class Upperlower {
public static void main (String[] args){
Scanner x = new Scanner(System.in);
String a;
System.out.println("Enter a line of text below:");
a = x.next();
String upper = a.toUpperCase();
String lower = a.toLowerCase();
System.out.println(upper);
System.out.println(lower);
}
But when I run it - I only get the first letter of the sentence I input back either Uppercase'd or lower.
Please help :D!
-
Re: Simple Java question
Look at which method of the Scanner class you are using. There are several different methods that return different parts of what you type in. The one you are using does NOT return a line of text. Find the method that will return the full line. See the API doc:
Java Platform SE 7
Please wrap your code in code tags. See: BB Code List - Java Programming Forum