Help!!!

+3 Bernard Pyc0d333 Parah · December 26, 2014
Hello guys, just started learning java a few weeks ago and i have been trying a few tasks. In this case i am trying to get this multiplication timetable to show in a horizontal format.




public class twoDimensional {
public static void main(String[] args) {
int j, b, c;

j = 2;
b = 12;

for (c = j; c <= b; c++)
{

System.out.println(" " + c);

for (int i= 1; i <= 10; i++)
{
System.out.println(i + " = " + (c * i));
}
System.out.println("\t");
}
}
}

this is the output i am getting:
 2
1 = 2
2 = 4
3 = 6
4 = 8
5 = 10
6 = 12
7 = 14
8 = 16
9 = 18
10 = 20
   

3
1 = 3
2 = 6
3 = 9
4 = 12
5 = 15
6 = 18
7 = 21
8 = 24
9 = 27
10 = 30
    
 4
1 = 4
2 = 8
3 = 12
4 = 16
5 = 20
6 = 24
7 = 28
8 = 32
9 = 36
10 = 40

continously till it gets to 12, but i want it to show in a table format please. thanks guys.

Post a Reply

Replies

Oldest  Newest  Rating
0 Stefan Gost · December 29, 2014
well try to use tabs (\t) but thats still not a good selution
0 Neil Cannon · December 28, 2014
Send outputs into an excel spreadsheet.
0 Bernard Pyc0d333 Parah · December 26, 2014
i have now used arrays to do it but i am still not getting the output as it should be.

public class twoDimensional
{
public static void main(String[] args)
{
int[][] array = new int[13][13];
for (int i=1; i<array.length; i++)
{
System.out.print(" " );
for (int j=2; j<array.length; j++)
{
array[j] = i*j;
System.out.print(" " + array[j]+" ");
}
System.out.print(" \n");
}
}
}


this is the output.

  2  3  4  5  6  7  8  9  10  11  12  
  4  6  8  10  12  14  16  18  20  22  24  
  6  9  12  15  18  21  24  27  30  33  36  
  8  12  16  20  24  28  32  36  40  44  48  
  10  15  20  25  30  35  40  45  50  55  60  
  12  18  24  30  36  42  48  54  60  66  72  
  14  21  28  35  42  49  56  63  70  77  84  
  16  24  32  40  48  56  64  72  80  88  96  
  18  27  36  45  54  63  72  81  90  99  108  
  20  30  40  50  60  70  80  90  100  110  120  
  22  33  44  55  66  77  88  99  110  121  132  
  24  36  48  60  72  84  96  108  120  132  144  

the problem is that i want the values to be well arranged in seperate columns
+1 Branislav Lazic · December 26, 2014
So, as far I understand, you want to inline your result for each number or what?
P.S. Also, give meaningful names to your questions, instead of "Help!!!"
  • 1

Java / Android Development

107,286 followers
About

Very popular language used to create desktop applications, website applets, and Android apps.

Links
Moderators
Bucky Roberts Administrator