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 8 of 8

Thread: Why the things in this code mean what they mean,an incomplete step and documentation help

  1. #1
    Junior Member
    Join Date
    Jan 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Why the things in this code mean what they mean,an incomplete step and documentation help

    Recently I got major help from tutor but I forget some of the stuff he said and (unlike the next time tomorrow) I didn't have a recorder on me at the time so I can't go back and refer to what he was saying -_- .

    I'd just like explanations to understand this.See even though my tutor graciously commented to the side what each line of code does I don't think I still know why what is there is there and how each statement works.

    This is the nearly done code.

    import java.util.Scanner;
     
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    import java.util.Scanner; // brings in library to read keyboard input
    //import java.lang.String;
     
    public class Lab1 {
     
        /**
         * @param args the command line arguments
         */
        public static void main(String[] args) 
        {
         Scanner usernum=new Scanner (System.in); //create object for keyboard input
     
           System.out.print("enter number of groups "); // ask user for a number
              int userInput = usernum.nextInt(); // takes keyboard input and put into variable userInput
     
           System.out.print("ASCII 1-127\n"); // print title
     
             for (int groups=0; groups<=127; groups=groups+1){ // loop until the counter is over userInput number
                  String dec=Integer.toString(groups); //convert to dec
                  String hex=Integer.toHexString(groups);  //convert dec to hex
                         char ascii=(char)groups; //convert dec to ascii
                  System.out.print(dec+" "+hex+" "+ascii+"    "); // print on screen
                    if ((groups % userInput)==0) {
                         System.out.print("\n");
                         }
                    }
                  System.out.print("\n");
                    }
     
    }

    This is the nearly done code.What questions are left of this is a step that says that "each group of small columns will be 8 chars wide and properly aligned for values less than 6".What does that mean when you got something like this?.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Why the things in this code mean what they mean,an incomplete step and documentation help

    What does the code print out when it executes?
    What is the purpose of the program?
    It looks like it gets some input from the user, does some computations and prints out something. That's a common thing for a program.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jan 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Why the things in this code mean what they mean,an incomplete step and documentation help

    Quote Originally Posted by Norm View Post
    What does the code print out when it executes?
    What is the purpose of the program?
    It looks like it gets some input from the user, does some computations and prints out something. That's a common thing for a program.
    What this code prints out when it executes is (when you type in a number from 0-127) the ASCII code table up until the number you typed in.Now that I'm speaking about that for some reason it's not doing that and just printing out the 127 ASCII table figures -_-.Seems like I might need help with that too `_` .

    Also,no offense but isn't that something that could be figured out just by looking at the code '~' ?.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Why the things in this code mean what they mean,an incomplete step and documentation help

    by looking at the code '~' ?.
    There are many subtle things in programming that can be missed. Why take a chance when it's so easy to compile and execute code to see what it does. And it's a lot easier and there is not doubts about what the code does. The printout shows it.

    Can you post the output for the program?

    the ASCII code table up until the number you typed in
    Are you sure? Execute the program with some different input values to see what it does.

    printing out the 127 ASCII table figures
    Which is it? ASCII codes up to the number entered
    or 127 codes?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Jan 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Why the things in this code mean what they mean,an incomplete step and documentation help

    Quote Originally Posted by Norm View Post
    There are many subtle things in programming that can be missed. Why take a chance when it's so easy to compile and execute code to see what it does. And it's a lot easier and there is not doubts about what the code does. The printout shows it.
    Thanks it makes sense.

    Quote Originally Posted by Norm View Post
    Can you post the output for the program?

    Are you sure? Execute the program with some different input values to see what it does.[/QUOTE]

    Hopefully these snippings of the screen output help.Sorry the sizes (i'd change them ASAP if I knew how) but the numbers are 2,23 and 123

    dl2.jpgdl23.jpgdl123.jpg


    Quote Originally Posted by Norm View Post
    Which is it? ASCII codes up to the number entered
    or 127 codes?
    it generates ASCII codes so long as you don't go beyond the number 127.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Why the things in this code mean what they mean,an incomplete step and documentation help

    What are your questions now?

    go beyond the number 127.
    What happens then?
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    Jan 2013
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Why the things in this code mean what they mean,an incomplete step and documentation help

    Quote Originally Posted by Norm View Post
    What are your questions now?


    What happens then?
    Oh it's all good now man,thanks 4 your help.Now I just got a question about how to do good java documentation which is an easy quarter's worth of my mark.Would you (or anyone else) be able to show me some a/o a good example of well done java documentation in a program's code would you?

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Why the things in this code mean what they mean,an incomplete step and documentation help

    good example of well done java documentation in a program's code
    That will be very very hard to find looking at student code on the forums. I see a well documented program about once a month.

    Look at the source code that comes with the JDK. It's in a zip file: src.zip
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. On line step by step Java Tutorial
    By Sylva in forum The Cafe
    Replies: 3
    Last Post: August 11th, 2012, 05:34 PM
  2. Step by step process to implement SSL
    By balajikrb@gmail.com in forum Java Networking
    Replies: 0
    Last Post: April 20th, 2012, 09:55 AM
  3. Java API Documentation Needed
    By malikashtermehdy in forum Java SE APIs
    Replies: 5
    Last Post: March 16th, 2012, 12:46 AM
  4. need code and documentation
    By Aparna in forum Threads
    Replies: 1
    Last Post: November 9th, 2011, 03:25 AM
  5. Array month/day/hour/min/sec incomplete java code
    By mightyking in forum Collections and Generics
    Replies: 12
    Last Post: September 18th, 2011, 08:46 PM