mport java.io.*;
class Exp23
{public static void main(String argl[])
{int n=20, m=5,result;
char op;
try { op=(char)(System.in.read());
if (op='+')
result=n+m;
else
{if(op='-')
result=n-m;
else
{if(op='*')
result=n*m;
else
if(op='/')
result=n/m;
else
System.out.println("operator input error");
}
}
if(op='+' || op='-' || op='*' || op='/')
System.out.println("result="+result);
}catch(IOException e) {System.out.println("in put error");}
}
}
class Exp23
{public static void main(String argl[])
{int n=20, m=5,result;
char op;
try { op=(char)(System.in.read());
if (op='+')
result=n+m;
else
{if(op='-')
result=n-m;
else
{if(op='*')
result=n*m;
else
if(op='/')
result=n/m;
else
System.out.println("operator input error");
}
}
if(op='+' || op='-' || op='*' || op='/')
System.out.println("result="+result);
}catch(IOException e) {System.out.println("in put error");}
}
}
解决方案 »
- 如何查找UTF-8字符串中的字符串?(字符编码问题)
- 新手请教一个窗体事件小程序。。。
- jsp在a b2个页面传递变量 session如何定义
- JAVA怎样得到当前程序的路径
- 菜鸟提问:Hello world程序在eclipse下能正确的运行但是在DOS下就是总出错,
- java 怎么学?
- 發郵件附件為.html文件。我想通過郵件正文直接把.html的內容顯示在正文中。急急急(只有40分)
- servlet 中能直接调用javaBean 吗?
- jtextarea显示的问题
- 求高手点拨一个“Java项目的移植调试”的问题..
- 目前有比较靠谱的Java飞信API用来发信息么,09年以前的好像都不能用了。
- 这样的项目没见过,请高手指点
System.out.println("result="+result);这句也不对吗?
Exp23.java:23: variable result might not have been i
System.out.println( "result="+result);
为什么这句话也有问题,该怎么做呢?
^
这个错误的级别高一些,意思是result可能没有赋值,所以不能通过编译,解决方式很简单:就是给它赋与初始值,修改第一行代码,比如:
int n=20, m=5,result =0;
int n=20, m=5,result =Integer.MIN_VALUE;