Results 1 to 2 of 2
  1. #1
    devinmont is offline Member
    Join Date
    Sep 2012
    Posts
    1
    Rep Power
    0

    Default 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!

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,318
    Rep Power
    25

    Default 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
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Simple java applet zoom question
    By Lemmy Winks in forum New To Java
    Replies: 4
    Last Post: 07-02-2012, 03:17 AM
  2. A simple question
    By Rylogy in forum AWT / Swing
    Replies: 2
    Last Post: 02-15-2012, 01:54 AM
  3. Simple question on Embedding Java applets
    By gasper91 in forum New To Java
    Replies: 6
    Last Post: 06-14-2011, 03:24 AM
  4. Question about a simple Java programing assignment.
    By ron_j_m in forum New To Java
    Replies: 12
    Last Post: 04-27-2011, 12:03 AM
  5. Replies: 2
    Last Post: 03-18-2010, 12:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •