Java——方法(练习九九乘法表)

public static void(int,byte…) xxx(int a,int b)
修饰符 返回值类型 方法名(参数类型 参数名1,参数类型 参数名2…){
方法体语句;
return 返回值;

public class fangfa {
    public static void main(String[] args) {
        int qiuhe = add(10,20);
      //盘子 = 炒菜(地沟油,烂白菜...);
        System.out.println(qiuhe);
    }
    public static int add (int a,int b){     //定义一个a+b的方法
        int sum = a+b;
        return sum;
    }

    /*盘子 炒菜(油,菜...){
        炒菜的动作;
        return 一盘菜;
    }*/

}

题目:根据键盘录入的数据输出对应的乘法表

import java.util.Scanner;
public class jiujiuchengfabiao {
    public static void main(String[] args) {
        Scanner wsq = new Scanner(System.in);
        int num =wsq.nextInt();
        chengfabiao(num);
    }
    public static void chengfabiao (int a){
        for(int i=1;i<=a;i++){
            for(int j=1;j<=i;j++){
            System.out.print(j + "*" + i + "=" + (i * j) + "\t");   
        }
        System.out.println();
    }   
  }
}

猜你喜欢

转载自blog.csdn.net/qq_41264055/article/details/80986347