首页 > 其它 > 题目详情
JAVA从键盘输入2个数字,输出两个数字的“+、-、*、/、%”的运算表达式及运算结果
题目内容:
JAVA从键盘输入2个数字,输出两个数字的“+、-、*、/、%”的运算表达式及运算结果优质解答
import java.util.Scanner;
public class Test01 {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
float num1,num2;
System.out.print("请输入两个数!\n第一个数:");
num1=scan.nextFloat();
System.out.print("第二个数:");
num2=scan.nextFloat();
System.out.println(num1+"+"+num2+"="+(num1+num2));
System.out.println(num1+"-"+num2+"="+(num1-num2));
System.out.println(num1+"*"+num2+"="+(num1*num2));
System.out.println(num1+"/"+num2+"="+(num1/num2));
System.out.println(num1+"%"+num2+"="+(num1%num2));
}
}
优质解答
public class Test01 {
public static void main(String[] args) {
Scanner scan=new Scanner(System.in);
float num1,num2;
System.out.print("请输入两个数!\n第一个数:");
num1=scan.nextFloat();
System.out.print("第二个数:");
num2=scan.nextFloat();
System.out.println(num1+"+"+num2+"="+(num1+num2));
System.out.println(num1+"-"+num2+"="+(num1-num2));
System.out.println(num1+"*"+num2+"="+(num1*num2));
System.out.println(num1+"/"+num2+"="+(num1/num2));
System.out.println(num1+"%"+num2+"="+(num1%num2));
}
}
本题链接: