Results 1 to 6 of 6
Thread: Controlling User Inputs
- 05-29-2011, 11:40 PM #1
Member
- Join Date
- May 2011
- Posts
- 2
- Rep Power
- 0
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.
- 05-29-2011, 11:43 PM #2
Member
- Join Date
- Jan 2011
- Location
- Gainesville, FL
- Posts
- 45
- Rep Power
- 0
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.
-
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!
- 05-30-2011, 02:40 PM #4
Member
- Join Date
- May 2011
- Posts
- 2
- Rep Power
- 0
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!
-
- 05-30-2011, 02:50 PM #6
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,405
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Sum positive numbers using 10 inputs from user
By pvictory1 in forum New To JavaReplies: 15Last Post: 10-10-2010, 01:30 AM -
Controlling cmd from java...HELP!!
By eponcedeleon in forum Advanced JavaReplies: 12Last Post: 02-23-2010, 06:33 PM -
[SOLVED] How do I make user inputs appear bolded??
By mjm1189 in forum EclipseReplies: 0Last Post: 09-13-2008, 12:59 AM -
Java program that stores user inputs
By staticy2003 in forum Advanced JavaReplies: 6Last Post: 01-24-2008, 07:46 PM -
controlling GC
By ravian in forum EclipseReplies: 2Last Post: 01-03-2008, 08:13 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks