代码:
package com.java.demo1;
import java.util.Scanner;
public class JSQi {
public static void main(String[] args) {
double a,b;
String str,str2;
char ch;
double m=0;
char ch2;
do {
System.out.println("请输入第一个数:");
Scanner reader=new Scanner(System.in);
a=reader.nextDouble();
System.out.println("请输入第二个数:");
Scanner reade=new Scanner(System.in);
b=reade.nextDouble();
System.out.println("请输入运算符(+,-,*,/):");
Scanner read=new Scanner(System.in);
str=read.next();
ch=str.charAt(0);
switch(ch) {
case '+':
m=a+b;break;
case '-':
m=a-b;break;
case '*':
m=a*b;break;
case '/':
m=a/b;break;
}
System.out.println("结果是:"+m);
System.out.println("请问要退出吗?y/n");
Scanner rea=new Scanner(System.in);
str2=rea.next();
ch2=str2.charAt(0);//获取字符
if(ch2=='y') {
System.out.println("程序结束!");
break;
}
// break;
}
while(ch2=='n');
}
}