Ok, so I got this code from this person. public class addTableDriver { public st
ID: 3621133 • Letter: O
Question
Ok, so I got this code from this person.
public class addTableDriver {
public static void main ( String [] args ) {
Add table = new Add ( );
table.GetRows ( );
table.GetColumns ( );
table.PrintAddTable ( );
}
}
------------------------------------------
import java.util.*;
public class Add
{private int row,column;
public Add()
{row=0;
column=0;
}
public void GetRows ( )
{
Scanner input1= new Scanner(System.in);
do
{
System.out.print("Enter the number of rows to be shown " +
"( 2 - 30 ) -> ");
row= input1.nextInt();
}
while (row>30||row<2);
}
public void GetColumns ( )
{
Scanner input2= new Scanner(System.in);
do
{
System.out.print( "Enter the number of columns to be shown " +
"( 2 - 12 ) -> ");
column= input2.nextInt();
}
while (column>12||column<2);
}
public void PrintAddTable()
{String format;
int digits=4;
int i=0,j=0,k,rowupto;
for (i =1;i System.out.print(" ");
format=" | %"+digits+"d";
for (i =1;i<=column;i++)
System.out.printf(format,i);
System.out.println();
for (i =0;i<(digits+3)*(column+1);i++)
System.out.print("-");
System.out.println();
for (rowupto=1;rowupto<=row;rowupto++)
{for (i =1;i<=digits-4;i++)
System.out.print(" ");
System.out.printf("%3d",rowupto);
{
for(j=1;j<=column;j++)
System.out.printf(format,rowupto+j);
System.out.println();
}
}
}
}
The format that comes out is like this.
| 1| 2| 3| 4| 5| 6| 7|
-------------------------------------------------------
1 | 2| 3| 4| 5| 6| 7| 8|
2 | 3| 4| 5| 6| 7| 8| 9|
3 | 4| 5| 6| 7| 8| 9| 10|
But I want the format to be like this.
| 1| 2| 3| 4| 5| 6| 7|
-------------------------------------------------------
1 | 2 3 4 5 6 7 8
2 | 3 4 5 6 7 8 9
3 | 4 5 6 7 8 9 10
Could anyone help me with this?
Explanation / Answer
please rate - thanks
public class addTableDriver {
public static void main ( String [] args ) {
Add table = new Add ( );
table.GetRows ( );
table.GetColumns ( );
table.PrintAddTable ( );
}
}
----------------------------------------------------------
import java.util.*;
public class Add
{private int row,column;
public Add()
{row=0;
column=0;
}
public void GetRows ( )
{
Scanner input1= new Scanner(System.in);
do
{
System.out.print("Enter the number of rows to be shown " +
"( 2 - 30 ) -> ");
row= input1.nextInt();
}
while (row>30||row<2);
}
public void GetColumns ( )
{
Scanner input2= new Scanner(System.in);
do
{
System.out.print( "Enter the number of columns to be shown " +
"( 2 - 12 ) -> ");
column= input2.nextInt();
}
while (column>12||column<2);
}
public void PrintAddTable()
{String format;
int digits=4;
int i=0,j=0,k,rowupto;
for (i =1;i<digits;i++)
System.out.print(" ");
format=" | %"+digits+"d";
for (i =1;i<=column;i++)
System.out.printf(format,i);
System.out.println();
for (i =0;i<(digits+3)*(column+1);i++)
System.out.print("-");
System.out.println();
for (rowupto=1;rowupto<=row;rowupto++)
{for (i =1;i<=digits-4;i++)
System.out.print(" ");
System.out.printf("%3d",rowupto);
{format=" | %"+digits+"d";
System.out.printf(format,rowupto+j);
format=" %"+digits+"d";
for(j=2;j<=column;j++)
System.out.printf(format,rowupto+j);
System.out.println();
}
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.