Results 1 to 4 of 4
- 05-14-2012, 12:27 AM #1
Senior Member
- Join Date
- Apr 2012
- Posts
- 115
- Rep Power
- 0
How can I format this multi dimentional array?
This is my code
outputJava Code:package chapter_vii; import java.util.Scanner; public class Polling_7_38 { public static void main(String[] args) { Scanner input = new Scanner(System.in); String[] issues = new String[5]; issues[0] = "The economy"; issues[1] = "The availability of jobs"; issues[2] = "National security"; issues[3] = "Education"; issues[4] = "Usefulness of questionaires"; int[][] responses = new int[5][10]; int response; int people; System.out.println("How many people will take this survey?"); people = input.nextInt(); for( int i = 0 ; i < people ; i++ ) { for( int j = 0 ; j < issues.length ; j++ ) { System.out.println(issues[j]); response = input.nextInt(); ++responses[j][response]; } } for (int i = 0 ; i < responses.length ; i++) { System.out.printf("%50s", issues[i]); for ( int j = 0 ; j < responses[i].length ; j++) { System.out.print(" " + responses[i][j]); } System.out.println(""); } } }
This is the best I can do, but I want the question on the left and the responses lined up with themselves on the right... but this is a problem because their position is determined by the question, so tabs after the question will give different lengths. I cant format the inside loop because that will be applied to each elementJava Code:How many people will take this survey? 1 The economy 1 The availability of jobs 1 National security 1 1Education Usefulness of questionaires 1 The economy 0 1 0 0 0 0 0 0 0 0 The availability of jobs 0 1 0 0 0 0 0 0 0 0 National security 0 1 0 0 0 0 0 0 0 0 Education 0 1 0 0 0 0 0 0 0 0 Usefulness of questionaires 0 1 0 0 0 0 0 0 0 0
How can I format this?
-
Re: How can I format this multi dimentional array?
You could always use a negative format String:
System.out.printf("%-50s", issues[i]);
Although consider using a number smaller than 50.
- 05-14-2012, 03:33 AM #3
Senior Member
- Join Date
- Apr 2012
- Posts
- 115
- Rep Power
- 0
Re: How can I format this multi dimentional array?
thanks freind
didnt know you could do that
-
Similar Threads
-
Multi Array dec
By maya700 in forum New To JavaReplies: 5Last Post: 07-23-2011, 11:29 AM -
how to read a text delimited file using 2 dimentional array in java ??
By pooja123 in forum New To JavaReplies: 2Last Post: 04-01-2011, 03:04 PM -
multi or two dimensional array
By maya700 in forum New To JavaReplies: 4Last Post: 07-12-2010, 06:52 PM -
adding elemnts of two dimentional array into vector
By sara12345 in forum New To JavaReplies: 10Last Post: 12-31-2009, 11:07 AM -
Help with array multi-dimensional
By barney in forum New To JavaReplies: 1Last Post: 07-31-2007, 08:00 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks