Results 1 to 5 of 5
Like Tree1Likes
  • 1 Post By jim829

Thread: what's wrong with this code

  1. #1
    Tripleg is offline Member
    Join Date
    May 2014
    Posts
    1
    Rep Power
    0

    Default what's wrong with this code

    SHOUTS AND whispers.
    Write a program that reads in a line of text and then outputs that line of text first in all uppercase letters and then in all lowercase letters.

    INPUT and PROMPTS. The program prompts for a line of text as follows: "Enter the text: " and then reads in an entire line of text as a String .

    OUTPUT . There are four lines of output . The first line is "The text in all upper case is: ". The second line is the line that was read in, displayed in all uppercase. The third line is "The text in all lower case is: " and the fourth line is the original line that was read in, displayed in all lowercase.

    CLASS NAMES. Your program class should be called ShoutAndWhisper.

    [import java.util.Scanner;

    public class ShoutAndWhisper
    {
    public static void main(String[] args)
    {

    Scanner scannerObject = new Scanner(System.in);
    System.out.println("Enter the text: " );

    String toUpperCase = scannerObject.nextLine();
    String toLowerCase = scannerObject.next();

    System.out.println("The text in all upper case is: \n" + toUpperCase);
    System.out.println("The text in all lower case is: \n" + toLowerCase);
    }
    }]
    [/CODE]

  2. #2
    AlexGraal is offline Señor Member
    Join Date
    Jan 2014
    Posts
    175
    Rep Power
    0

    Default Re: what's wrong with this code

    What happens when you run it? What do you expect to happen? What is the difference?

  3. #3
    Join Date
    Jun 2014
    Posts
    2
    Rep Power
    0

    Default Re: what's wrong with this code

    It seems that you are misunderstanding the methods "nextLine" and "next" and they have different meanings. Besides that, if you want to pass a string to upper or lower case you should take a look to toUpperCase() and toLowerCase() functions.
    Last edited by developerprincess; 06-03-2014 at 05:17 AM.

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,501
    Rep Power
    5

    Default Re: what's wrong with this code

    Please do not spoon feed solutions to posters on this forum (it is especially frowned upon to do what appears to be their homework for them). It is better to help them figure out the problem themselves. Otherwise they will not learn to program on their own. You might consider deleting your post and let the OP (original poster) figure this out on his/her own.

    Regards,
    Jim
    developerprincess likes this.
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  5. #5
    Join Date
    Jun 2014
    Posts
    2
    Rep Power
    0

    Default Re: what's wrong with this code

    Ok! I already edited my response. Sorry about the inconveniences. I'm new in this forum, thanks for your advice!

Similar Threads

  1. What is wrong in my code
    By janmjeay in forum New To Java
    Replies: 3
    Last Post: 06-08-2013, 04:56 AM
  2. What's wrong with my code?
    By Isong in forum AWT / Swing
    Replies: 1
    Last Post: 11-16-2010, 06:00 PM
  3. What is wrong with this code
    By rosh72851 in forum New To Java
    Replies: 13
    Last Post: 10-31-2008, 01:50 AM
  4. what's wrong with this code?
    By agenteleven in forum Advanced Java
    Replies: 5
    Last Post: 10-07-2008, 11:26 AM
  5. What's wrong with this code?
    By Wizard wusa in forum New To Java
    Replies: 14
    Last Post: 01-22-2008, 11:55 PM

Tags for this Thread

Posting Permissions

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