-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFunctionTest3.java
More file actions
58 lines (49 loc) · 1.12 KB
/
FunctionTest3.java
File metadata and controls
58 lines (49 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/*
需求:键盘录入行数和列数,输出对应的星星
import java.util.Scanner;
class FunctionTest3{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("请输入行数:");
int a=sc.nextInt();
System.out.println("请输入列数:");
int b=sc.nextInt();
print(a,b);//单独调用
}
public static void print(int n,int m){
for(int x=1;x<=n;x++){
for(int y=1;y<=m;y++){
System.out.print("*");
}
System.out.println();
}
}
}
*/
/*
需求:键盘录入一个数据n(1<=n<=9),输出对应的乘法表
*/
import java.util.Scanner;
class FunctionTest3{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("请输入数据n(1<=n<=9):");
int n=sc.nextInt();
//判断n数据的合理行
if(n<1 ||n>9){
System.out.println("输入数据有误");
}else{
nine(n);//单独调用方法
}
//nine(n); 数据N>9
}
//方法nn乘法表
public static void nine(int m){
for(int a=1;a<=m;a++){
for(int b=1;b<=a;b++){
System.out.print(a+"*"+b+"="+a*b+" ");
}
System.out.println();
}
}
}