Output Format Java -
i have assignment q , have of done need output neater. need ask user choose num of rows between 3-10 , num of columns between 5-10.
- but output needs have number spaced evenly apart can't working!!?
- i need validate users input... how?
sample code:
scanner s = new scanner(system.in); system.out.print("please enter number of rows between range of 3 10: "); int count1 = s.nextint(); system.out.print("please enter number of columns between range of 5 10: "); int count2 = s.nextint(); (int = 1; <= count1; i++) { (int j = 1; j <= count2; j++) { system.out.print((i * j) + " "); } system.out.println(""); } } }
i rather leave comment, yay less 50 reputation. take @ following links, should provide insight:
a similar stackoverflow question
java output formatting strings
and java documentation
http://docs.oracle.com/javase/6/docs/api/java/util/formatter.html#syntax
hope you.
edit:
in answer second question, comment suggesting loop place start. similar following:
system.out.print("please enter number of rows between range of 3 10: "); int count1 = s.nextint(); while (count1 < 3 || count1 > 10) { system.out.print("that not valid input. try again: "); count1 = s.nextint(); } and of course same count2. make separate function , pass count1 , count2 separately reduce duplicate code. loop condition here count1 < 3 || count1 > 10 continue prompt user input until within acceptable range.

Comments
Post a Comment