Home > Back-end >  Java jiujiu multiplication tables for help
Java jiujiu multiplication tables for help

Time:10-19

Just learning Java does not understand, how to implement the input multiple sets of test data,, every brother please help

Subject requirements, in the pictures, thank you,

CodePudding user response:

If you want to enter n sets of data, you can use a two-dimensional array n rows 3 columns to store test data is not to go, you input the for loop always

CodePudding user response:

I also is new this question is what I can't understand you, but let me write a jiujiu multiplication tables or broadly to
For (int x=1; x<=9; X++) {
For (int y=1; Y<=x; Y++) {
System. The out. Print (" * "+ x + y +"="+ x * y +" \ t ");
}
System.out.println();
}

CodePudding user response:

refer to the original poster ink nine south smoke reply:
just learning Java do not understand, how to implement the input multiple sets of test data,, every brother please help


 
Public class Test {
Public static void main (String [] args) {
Int T;
Scanner sc=new Scanner(System.in);
While (true) {
System. The out. Print (" please enter a positive integer T (1 & lt;=T<=100) : ");
T=sc. NextInt ();
If (T>=1 & amp; & T<=100) break;
System. The out. Println (" input error please enter again ");
}
Int [] [] array=new int [T] [3].
for(int i=1; i<=T; I++) {
System. The out. Println (" please enter the first "+ I +" group of three separated data center has Spaces ");
For (int j=0; J<3; J++) {
Array [I - 1) [j].=sc nextInt ();
}
}
for(int i=0; iThe switch (array [I] [0]) {
Case 1: {
System. The out. Println (array [I] [1] * array [I] [2]).
break;
}
Case 2: {
System. Out. Println (the String. Format (" % 9 s ", array [I] [1] + "*" + array [I] [2] + "=" + array [I] [1] * array [I] [2]));
break;
}
Case 3: {
Int the Max and min.
If (array [I] [1] & gt;=array [I] [2]) {
Max=array [I] [1];
Min=array [I] [2];
} else {
Max=array [I] [2];
Min=array [I] [1];
}
For (int j=min; J<=Max; J++) {
System. Out. Print (the String. Format (" % 9 s, j + "*" + Max + "=" + j * Max));
}
System.out.println();
break;
}
Case 4: {
Int the Max and min.
If (array [I] [1] & gt;=array [I] [2]) {
Max=array [I] [1];
Min=array [I] [2];
} else {
Max=array [I] [2];
Min=array [I] [1];
}
For (int j=Max; J<=9; J++) {
System. Out. Print (the String. Format (" % 9 s, "min +" * "+ j +"="+ min * j));
}
System.out.println();
break;
}
Case 5: {
Int the Max and min.
If (array [I] [1] & gt;=array [I] [2]) {
Max=array [I] [1];
Min=array [I] [2];
} else {
Max=array [I] [2];
Min=array [I] [1];
}
for(int j=1; J<=Max; J++) {
For (int k=1; K<=min; K++) {
If (k> J) break;
System. Out. Print (the String. Format (" % 9 s, k + "*" + j + "=" + j * k));
}
System.out.println();
}
}
}
}
}
}

  • Related