A:求两个数据之和
B:判断两个数据是否相等
C:获取两个数中较大的值
D:打印m行n列的星形矩形
E:打印nn乘法表
import java.util.Scanner;
class Demo6 {
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();
int sum = add(a,b);
System.out.println(sum);
int max = getMax(a,b);
System.out.println(max);
/*print(a,b); */
print(a);
}
public static int add (int a,int b){
int add = a + b;
return add;
}
public static int getMax(int a,int b) {
int getmax = (a > b ) ? a : b;
return getmax;
}
/*public static void print (int a,int b){
for (int i=1;i<=a;i++)
{for (int j=1;j<=b;j++) {
System.out.print("*");
}System.out.println();
}*/
public static void print (int a){
for (int i=1;i<=a;i++) {
for (int j=1;j<=i;j++) {
System.out.print(j+"*"+i+"="+(j*i)+'\t');
}
System.out.println();
}
}
}
能只输出一种调用方法的结果吗?不改方法名,试了几次搞不好,请教!
|
|