請參考我的做法
import java.util.*;
public class Y5872 {
public static int mult() {
for (int i = 1; i <= 9; i++) {
for (int j = 1; j + i <= 10; j++) {
System.out.print(i + "*" + j + "=" + i*j + " ");
}
System.out.println();
}
return 1;
}
public static int mult(int i) {
if (i <= 0) return -1;
for (int x = 1; x <= i; x++) {
for (int y = 1; y <= i; y++) {
System.out.print(x + "*" + y + "=" + x*y + " ");
}
System.out.println();
}
return 1;
}
public static int mult(int i, int j) {
if (i <= 0 || j <= 0) return -1;
for (int x = 1; x <= i; x++) {
for (int y = 1; y <= j; y++) {
System.out.print(x + "*" + y + "=" + x*y + " ");
}
System.out.println();
}
return 1;
}
public static int mult(int x[][]) {
for (int i = 0; i < x.length; i++) {
for (int j = 0; j < x[i].length; j++) {
x[i][j] = x.length * x[i].length;
}
}
return 1;
}
public static void main(String[] args) {
mult();
Scanner scan = new Scanner(System.in);
while (true) {
System.out.print("Enter i: ");
int i = Integer.parseInt(scan.next());
if (mult(i) == 1) break;
}
while (true) {
System.out.print("Enter i: ");
int i = Integer.parseInt(scan.next());
System.out.print("Enter j: ");
int j = Integer.parseInt(scan.next());
if (mult(i, j) == 1) break;
}
System.out.print("Enter i: ");
int i = Integer.parseInt(scan.next());
System.out.print("Enter j: ");
int j = Integer.parseInt(scan.next());
int[][] x = new int[i][j];
mult(x);
for (int[] ary : x) {
System.out.println(Arrays.toString(ary));
}
}
}
- Jun 13 Wed 2012 12:26
請幫幫我java程式 不好意思 有點多
close
LV超3A名牌購物網
全站熱搜
留言列表