编写程序实现如下界面效果:
import java.util.Scanner;public class Test01 {public static void main(String[] args) {String name;Scanner input = new Scanner(System.in);System.out.println("请输入您的姓名:");name = input.nextLine();System.out.println(name+",您好!欢迎学习Java。");}}
编写字符界面版计算器程序,运行时提示输入两个操作数,然后输出加减乘除运行结果。
import java.util.Scanner;
public class Test02 {public static void main(String[] args) {double number1,number2;System.out.println("=======字符版计算器=======");Scanner input = new Scanner(System.in);System.out.print("请输入第一个操作数:x=");number1 = input.nextDouble();System.out.print("请输入第二个操作数:y=");number2 = input.nextDouble();System.out.println("运算结果如下:");System.out.println("x+y="+(number1+number2));System.out.println("x-y="+(number1-number2));System.out.println("x*y="+(number1*number2));if(number2 != 0){System.out.println("x/y="+(number1/number2));}else {System.out.println("除数为0,运算无意义。");}}}
修改第(2)题程序,使得程序输出的运算结果中,能直接显示所输入的数据,而不是x+y之类。
import java.util.Scanner;
public class Test02 {public static void main(String[] args) {double number1,number2;System.out.println("=======字符版计算器=======");Scanner input = new Scanner(System.in);System.out.print("请输入第一个操作数:x=");number1 = input.nextDouble();System.out.print("请输入第二个操作数:y=");number2 = input.nextDouble();System.out.println("运算结果如下:");System.out.println(number1+"+"+number2+"="+(number1+number2));System.out.println(number1+"-"+number2+"="+(number1-number2));System.out.println(number1+"*"+number2+"="+(number1*number2));if(number2 != 0){System.out.println(number1+"/"+number2+"="+(number1/number2));}else {System.out.println("除数为0,运算无意义。");}}}