黑马程序员技术交流社区
标题:
今天编写了一个计算器小程序 有错误 求指教
[打印本页]
作者:
lsunshine
时间:
2015-7-13 22:20
标题:
今天编写了一个计算器小程序 有错误 求指教
import java.util.Scanner;
import java.lang.Exception;
class Program
{
public static void main(String[] args)
{ Scanner sc = new Scanner(System.in);
try
{
System.out.println("请输入一个数A:");
int a = sc.nextInt();
System.out.println("请选择符号:+,-,*,/");
String strOperate = sc.nextLine();
System.out.println("您输入的是:"+a + strOperate);
System.out.println("请输入一个数B:");
int b = sc.nextInt();
int strResult = 0;
switch (strOperate)
{
case "+" :
strResult = a + b;
break;
case "-":
strResult = a - b;
case "*":
strResult = a * b;
break;
case "/":
if ( b == 0)
System.out.println("除数不能为0");
else
strResult = a / b;
break;
}
System.out.println("结果是:"+strResult);
}
catch (Exception ex)
{
System.out.println("您的输入有错:"+ex.getMessage());
}
}
}
复制代码
作者:
胡俊焰
时间:
2015-7-14 00:24
创建对象,亲
作者:
lsunshine
时间:
2015-7-14 21:35
胡俊焰 发表于 2015-7-14 00:24
创建对象,亲
今天问了导师 终于弄明白了
作者:
胡俊焰
时间:
2015-7-15 00:03
lsunshine 发表于 2015-7-14 21:35
今天问了导师 终于弄明白了
怎么说的,?讲解一下!
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2