Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 11 of 11

Thread: Translate code

  1. #1
    Junior Member
    Join Date
    Dec 2013
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Translate code

    I need this code translated into English. The question is to write this code like u r explaining it, line by line. Exactly what is going on in each line


    I don't know to much so if u go line by line exactly what's happening I'd really appreciate it!

    Thanks
    Attached Images Attached Images


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,310
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: Translate code

    Can you copy the text and paste it here?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Dec 2013
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Translate code

    Import csl.Keyboard;
    Public class LetterCount
    {
    Public static void main (String[] args)
    {
    Final int NUMCHARS = 26;
    Int[] upper = new int[NUMCHARS];
    Int[] lower = new int[NUMCHARS];

    Char current;
    Int other = 0;

    System.out.println ("Enter a sentence:");
    String line = Keyboard.readStrimg();

    For (int ch = 0; ch < line.length(); ch++)
    {
    Current = line.charAt(ch);
    If (current >= 'A' && current <= 'Z')
    Upper[current-'A']++;
    Else
    If (current >= 'a' && current <= 'z')
    Lower [current-'a']++;
    Else
    Other ++;
    }

    System.out.println ();
    For (int letter=0; letter < upper.length; letter++)
    {
    System.out.print ( (char) (letter + 'A') );
    System.out.print (": " + upper[letter]);
    System.out,print ("\t\t" + (char) (letter + 'a') );
    System.out.println (": " + lower[letter]);
    }

    System.out.println ();
    System.out.println ("Non-alphabetic characters: " + other);
    }
    }

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,310
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: Translate code

    What are your questions about the code that was posted?
    What parts are not "English"? All java's keywords are English.

    What happens when you compile and execute the code?

    Please edit your post and wrap your code with code tags:
    [code=java]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Dec 2013
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Translate code

     
    Import csl.Keyboard;
    Public class LetterCount
    {
    Public static void main (String[] args)
    {
    Final int NUMCHARS = 26;
    Int[] upper = new int[NUMCHARS];
    Int[] lower = new int[NUMCHARS];
     
    Char current;
    Int other = 0;
     
    System.out.println ("Enter a sentence:");
    String line = Keyboard.readStrimg();
     
    For (int ch = 0; ch < line.length(); ch++)
    {
    Current = line.charAt(ch);
    If (current >= 'A' && current <= 'Z')
    Upper[current-'A']++;
    Else
    If (current >= 'a' && current <= 'z')
    Lower [current-'a']++;
    Else
    Other ++;
    }
     
    System.out.println ();
    For (int letter=0; letter < upper.length; letter++)
    {
    System.out.print ( (char) (letter + 'A') );
    System.out.print (": " + upper[letter]);
    System.out,print ("\t\t" + (char) (letter + 'a') );
    System.out.println (": " + lower[letter]);
    }
     
    System.out.println ();
    System.out.println ("Non-alphabetic characters: " + other);
    }
    }






    I need to say what each line of the code does. Line by line, what does each line do

    --- Update ---

    And ignore the Capitol letters at the start of the lines. They should be lower case

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,310
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: Translate code

    Have you tried to compile and execute the program to see what it prints out when it executes? That will help you understand what the code is doing.

    If you need further explanation of what each statement does, add a println() statement after every assignment statement that shows what was assigned to the variable. For example:
      int x = 20*5/3;      // assign a value to x
      System.out.println("x="+x);   // show value of x


    BTW the code needs formatting. Most of the statements need to be indented to show the nesting logic.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Dec 2013
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Translate code

    Yeah I've ran the program but I need to see what each lines does, like u showed in your example but with my code. If you could do that that would be awesome!

  8. #8
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    6,304
    My Mood
    Mellow
    Thanks
    252
    Thanked 778 Times in 763 Posts

    Default Re: Translate code

    Why don't you comment the code first, and then ask us whether we agree with your comments?

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,310
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: Translate code

    I've ran the program
    Can you post the version that will compile and execute. What is posted won't compile.
    Also add the println statements that I suggested be added in post#6.

    Then compile and execute the program and copy what it prints out and paste it here.
    If you don't understand my answer, don't ignore it, ask a question.

  10. #10
    Junior Member
    Join Date
    Dec 2013
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Translate code

    I'm not sure what to comment that's why I'm asking. And I don't have access to compile the program. The first pictures I posted r the exact code from my textbook. I can post a pic of the output if u need

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,310
    Thanks
    56
    Thanked 2,373 Times in 2,344 Posts

    Default Re: Translate code

    If you want any more here, do as I suggested in post#9. If you can't fix the program and compile it today, it's ok if you take whatever time you need to do it.

    Waiting for the corrected code and its output.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. How to Translate working code into code with a Tester Class
    By bankoscarpa in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 15th, 2012, 03:13 PM
  2. [SOLVED] Google translate API
    By vozmen in forum Java ME (Mobile Edition)
    Replies: 8
    Last Post: December 14th, 2011, 07:06 AM
  3. Translate Turbo Pascal code in Java
    By Mercenaire in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 4th, 2011, 04:52 AM
  4. Help to translate from C to java
    By ighor10 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 27th, 2010, 08:36 AM
  5. Translate Java Code Into English
    By drkossa in forum Java Theory & Questions
    Replies: 4
    Last Post: November 27th, 2009, 02:52 PM