Results 1 to 6 of 6
  1. #1
    time-space is offline Member
    Join Date
    May 2011
    Posts
    2
    Rep Power
    0

    Default Controlling User Inputs

    I have generated an ascii chart from 0-127; however, I don’t know how to group these numbers into columns depending on how many columns the user wishes.

    Ex:If the user wishes 6 columns
    1 2 3 4 5 6
    7 8 9 10 11 12
    Ex:If the user wishes 3 columns
    1 2 3
    4 5 6
    7 8 9
    10 11 12

    What I have so far...any help would be appreciated...

    Java Code:
    public class Practice05 
    {
        public static void main(String[] args) 
        {
           Scanner input = new Scanner(System.in);
           int num_group;
           
           System.out.println("How Many Groups?");
           num_group = input.nextInt();
          
            for (int x = 0; x<128; x++)
            {
                System.out.printf("%C %X %d\n", x, x, x );
                    
            }
        }
    }
    Last edited by time-space; 05-30-2011 at 03:04 PM.

  2. #2
    Vase is offline Member
    Join Date
    Jan 2011
    Location
    Gainesville, FL
    Posts
    45
    Rep Power
    0

    Default

    So the question you ask the user is how many columns, correct?

    If the user wants 6 columns, use a conditional to print a "\n" after every 6 characters printed.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    I would use a nesting of two for loops, the first for each row and the second for loop for each column. Inside I'd use printf to print out one column's worth of information. Don't forget to add a System.out.println after the inner for loop though to advance to the next row.

    Also, I've added code tags to your post. To learn how to do this yourself, please see the link in my signature.

    Much luck and welcome to Java-Forums.org!

  4. #4
    time-space is offline Member
    Join Date
    May 2011
    Posts
    2
    Rep Power
    0

    Default

    This is the approach I am trying to take ; however, I'm having a hard time with actually writing it. How would I implement the user input into the condition?

    Thank you!

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by time-space View Post
    This is the approach I am trying to take ; however, I'm having a hard time with actually writing it. How would I implement the user input into the condition?
    !
    You've already got code to get the user input. You simply use that number as the upper bound in one of your for loops and 300/userNumber for the other for loop. Experiment with it and find out what works. That's half the fun of programming.

  6. #6
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,365
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by time-space View Post
    I have generated an ascii chart from 0-300
    ASCII defines only 128 code points, the values in the range [0, 127].

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Sum positive numbers using 10 inputs from user
    By pvictory1 in forum New To Java
    Replies: 15
    Last Post: 10-10-2010, 01:30 AM
  2. Controlling cmd from java...HELP!!
    By eponcedeleon in forum Advanced Java
    Replies: 12
    Last Post: 02-23-2010, 06:33 PM
  3. Replies: 0
    Last Post: 09-13-2008, 12:59 AM
  4. Java program that stores user inputs
    By staticy2003 in forum Advanced Java
    Replies: 6
    Last Post: 01-24-2008, 07:46 PM
  5. controlling GC
    By ravian in forum Eclipse
    Replies: 2
    Last Post: 01-03-2008, 08:13 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
  •