Results 1 to 2 of 2
Thread: Simple Java question
- 09-11-2012, 07:27 PM #1
Member
- Join Date
- Sep 2012
- Posts
- 1
- Rep Power
- 0
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!
- 09-11-2012, 10:15 PM #2
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 ForumIf you don't understand my response, don't ignore it, ask a question.
Similar Threads
-
Simple java applet zoom question
By Lemmy Winks in forum New To JavaReplies: 4Last Post: 07-02-2012, 03:17 AM -
A simple question
By Rylogy in forum AWT / SwingReplies: 2Last Post: 02-15-2012, 01:54 AM -
Simple question on Embedding Java applets
By gasper91 in forum New To JavaReplies: 6Last Post: 06-14-2011, 03:24 AM -
Question about a simple Java programing assignment.
By ron_j_m in forum New To JavaReplies: 12Last Post: 04-27-2011, 12:03 AM -
Java Native Access (JNA) really simple begginer question
By carek in forum Advanced JavaReplies: 2Last Post: 03-18-2010, 12:39 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks