Results 1 to 12 of 12
  1. #1
    JacobM is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default Need some help with my homework.

    Hey everyone. I'm rather new to Java, and I have registered for this course rather late. I have been looking at tutorials online for certain things, and I just don't understand. The only language I have ever written in was Basic, and it was way simpler haha.

    Basically for this assignment, we have to create an ASCII table. I'll show the requirements.

    # Prompt the user for an integer which will define the number of groups in your table.
    # Produce an ASCII table from 0 to 127.
    # Your table will be organized into groups of three little columns displaying the same value as a character, in hexadecimal and in decimal value. So each number in the table is displayed three times.
    # Each of the groups of little columns will be 8 characters wide and neatly aligned (see sample output below). The alignment has to be neat for values less than 6. What is shown is just an example.
    # Leave 4 blank spaces between groups.
    # When you have printed the number of groups defined by the user input start a new line and continue.
    # When you reach 127, stop printing regardless of which group you are in and print one extra newline character.

    This is what I have so far.
    Java Code:
    import java.util.Scanner;
    public class Main {
    
    
        public static void main(String[] args) {
            
            
        Scanner Number = new Scanner(System.in);
        System.out.println("Please enter a number: ");
    
        int usernum = Number.nextInt();
    
        while (usernum < 128){
            while(usernum < 8){
                if (int Number = 6){
                   System.out.println("")
                           
                 
                }else if (Number=9){
                        System.out.println("");
        }
                    else if (Number=13){
                        
                       }
                        
               }
                
            
            
            }
    I'm not too sure where to go from here as my else if statements are not working as I had intended. Thanks!
    Last edited by JacobM; 02-04-2011 at 02:07 AM.

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    If you get an error then post an EXACT copy of the message.

    Take a close look at your if statement. Anything about it look odd? Compare it to the 2 else if statements.

  3. #3
    JacobM is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default

    If you are talking about the int, I have tried it with and without.

    The problem is, I don't even know where to go from here as I am a beginner.

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    What do you expect from us? You provide no information, so what help can we give you?

  5. #5
    JacobM is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default

    Okay fine, ill start with the first one, how would I even go about creating an ASCII table using java?

  6. #6
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    Would you mind posting the sample output?

    this is code for printing ascii from 0 - 127

    Java Code:
    for(int i = 0; i < 127; i++){
      System.out.println((char)i);
    }
    This gives you an idea, but without some sample output I dont understand exactly what you want.

  7. #7
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    Well I have a few problems with the assignment and if I was you I go and ask the teacher for clarification.

    # Prompt the user for an integer which will define the number of groups in your table.
    What does "groups" mean/represent. Especially in the 3rd point it says out put will be in 3 groups. So why does user have to enter a value for "groups".

    # Produce an ASCII table from 0 to 127.
    What does ASCII table mean (more below).

    # Your table will be organized into groups of three little columns displaying the same value as a character, in hexadecimal and in decimal value. So each number in the table is displayed three times.
    By character does it mean when value is 65 then it should display 'A', 66 display 'B' etc. If yes then for values 0 - 31 the character is non-viewable.

    # Each of the groups of little columns will be 8 characters wide and neatly aligned (see sample output below). The alignment has to be neat for values less than 6. What is shown is just an example.
    This can be achieved with the System.out.printf method or String.format method.

  8. #8
    JacobM is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default



    This is what my assignment is supposed to look like in the end. I think I am supposed to ask the user for the number of columns.

    I was wondering if there was a way to do like

    Java Code:
    Systems.out.print("0");
    Systems.out.print("1");
    Systems.out.print("2");
    Systems.out.print("3");
    Systems.out.print("4");
    Systems.out.println("5");
    If the user enters a 6. I know this is not the most efficient way, but I feel as if that is the only way to get what I am looking for.

  9. #9
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    I dono if you forgot to post the sample output but I am still too unclear on what the exercise wants you to do. What is a group?

  10. #10
    JacobM is offline Member
    Join Date
    Feb 2011
    Posts
    5
    Rep Power
    0

    Default

    Sorry. Here is the output.

    ImageShack® - Online Photo and Video Hosting

    IMG tags are not working.

  11. #11
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,755
    Rep Power
    7

    Default

    OK, now I understand the "groups" part.

    So what exact problem are you having? You simply need two nested loops. One to go across the page and one to go down the page. With a special escape clause when you hit 127. As mentioned above for each individual group you can use printf or format method to output display in the desired spacing.

  12. #12
    sunde887's Avatar
    sunde887 is offline Moderator
    Join Date
    Jan 2011
    Location
    Richmond, Virginia
    Posts
    3,069
    Blog Entries
    3
    Rep Power
    8

    Default

    I am not great with printf and String.format so I will leave that to other people but my idea is this. Have the loop step up by i + group amount each time Then you would want to print the int, char, hex value each time. You will probably need 2 loops to do this.

    if you do 3 groups it would be
    Java Code:
    for(int i = 0; i < 128; i += 3){
      System.out.print(i);
      System.out.print(" " + (i + 1));
      System.out.println(" " + (i + 2));
    }
    However, there is a huge flaw with this code, I am leaving fixing that part up to you.

    my hint to you however, is to use a nested loop from 0 to groups - 1.

Similar Threads

  1. Homework help
    By rclausing in forum New To Java
    Replies: 26
    Last Post: 11-24-2009, 06:06 AM
  2. Please Help with Homework
    By theuser in forum Advanced Java
    Replies: 2
    Last Post: 07-30-2009, 03:37 PM
  3. help with homework
    By pinkdiamondgail in forum Advanced Java
    Replies: 7
    Last Post: 04-07-2009, 01:34 AM
  4. Homework help...
    By robrobrob in forum New To Java
    Replies: 4
    Last Post: 10-17-2008, 04:24 AM

Posting Permissions

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