Java教程

Java 浅做计算机

本文主要是介绍Java 浅做计算机,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
package www.nihao;
import java.util.Scanner;
public class counter {
    public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);

    System.out.println("请输入两个操作数:");
    int number1 = scanner.nextInt();
    int number2 = scanner.nextInt();
    System.out.println("请选择你要计算的法则:");
    System.out.println("1.加法");
    System.out.println("2.减法");
    System.out.println("3.乘法");
    System.out.println("4.除法");
    int rule = scanner.nextInt();
    switch (rule) {
        case 1:
            System.out.println(add(number1, number2));
            break;
        case 2:
            System.out.println(minus(number1, number2));
            break;
        case 3:
            System.out.println(multiply(number1, number2));
            break;
        case 4:
            System.out.println(division(number1, number2));
            break;
        default:
            return;}

    scanner.close();
}

    
    public static int add(int a,int b){
        int sum;
        sum=a+b;
        return sum;
    }
    public static int minus(int a,int b){
        int sum;
        sum=a-b;
        return sum;
    }
    public static int multiply(int a,int b){
        int sum;
        sum=a*b;
        return sum;
    }
    public static int division(int a,int b){
        int sum;
        sum=a/b;
        return sum;
    }

}

  

这篇关于Java 浅做计算机的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!