excel规划求解,谢谢

我在做异常测试时,遇到一个不解的问题,网上找了资料也没见答案。在此贴出,希望各位大牛们能帮忙解惑。谢谢
问题描述:我在一个方法里面写了两个try,并在相应的catch语句后面都有输出语句用来判断方法是否因异常而终止。这样问题就来了,每次运行,输出的结果都不一样,有点随机的感觉。很是疑惑,为什么一段代码每次执行的输出结果不一样????
public class Test {
public static void main(String[] args) {
Object o = new String();
Integer i = (Integer)o;
}catch(Exception e) {
e.printStackTrace();
System.out.println("the code after ClassCastException_try");
int i = 9/0;
}catch(Exception e) {
e.printStackTrace();
System.out.println("the code after ArithmeticException_try");
//int j = 8/0;
String str = new String();
str = "hello world";
System.out.println(str);
输出结果有:
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
at Test.main(Test.java:6)
java.lang.ArithmeticException: / by zero
at Test.main(Test.java:13)
-----the code after ClassCastException_try
-----the code after ArithmeticException_try
-----hello world
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
at Test.main(Test.java:6)
-----the code after ClassCastException_try
java.lang.ArithmeticException: / by zero
at Test.main(Test.java:13)
-----the code after ArithmeticException_try
-----hello world
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
-----the code after ClassCastException_try
-----the code after ArithmeticException_try
-----hello world
at Test.main(Test.java:6)
java.lang.ArithmeticException: / by zero
at Test.main(Test.java:13)
java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Integer
at Test.main(Test.java:6)
java.lang.ArithmeticException: / by zero
-----the code after ClassCastException_try at Test.main(Test.java:13)
-----the code after ArithmeticException_try
-----hello world
为什么会出现这种情况,路过的请求解。谢谢
问题补充:hareamao 写道应该是PrintStream的实现问题,当多个输出在很短时间内做请求的时候,其顺序是不保证的。你但不调试的的话,肯定是顺序的结果。
是的,如果我设断点一步一步调试的话,输出的结果都是一样,按语句顺序来。
如果是你说的这样,为什么要要把printStream的实现弄成这样?? 有什么缘由吗?? 谢谢
问题补充:hareamao 写道换成System.err& 又手滑了
谢谢,换成System.err以后每次执行都是按顺序来输出的。跟你说的一样。
非常感谢你的帮助
采纳的答案
看了一下源代码,发现我说错了。
正确的原因是:printStackTrace用的是System.err管道。所以,如果你把程序中的System.out都换成System.out就肯定没问题了。out和err是两个从系统中得到的不同句柄,至于为什么不是顺序的,就是并发的问题了。
换成System.err& 又手滑了
应该是PrintStream的实现问题,当多个输出在很短时间内做请求的时候,其顺序是不保证的。你但不调试的的话,肯定是顺序的结果。
已解决问题
未解决问题英语,完形填空,求解,谢谢_百度知道
英语,完形填空,求解,谢谢
baidu&nbsp.baidu.hiphotos://d.baidu://d.com/zhidao/pic/item/35a85edf8db1cb13328a28bddebb8.jpg" target="_blank" title="点击查看大图" class="ikqb_img_alink"><img class="ikqb_img" src="<a href="http://d.com/zhidao/wh%3D600%2C800/sign=abc828baaf08ccd6fd57b1//zhidao/wh%3D450%2C600/sign=4e24c8db/35a85edf8db1cb13328a28bddebb8.hiphotos.jpg" esrc="http
提问者采纳
only their sons can touch THEM (碰她们) in public, if you touch an Indian person’s head by accident. It is just the t touch Indian women: A-B-D-A-B
B-D-C-D-AIndia is a country rich in tradition and culture, however. Indian people make LESS (较少) eye communication than Western people do. However, a friendly knock ON (轻拍拍) back between people of the same gender is allowed. If you are planning to travel to India, it would be helpful to know the following CUSTOMS (习俗), the head is the most important part of the human body, it is not proper to look straight into a person&#39. When it comes to other people.You should not hold hands with, such as hugging and kissing, stay away from the HEAD (别碰头部), India does not WELCOME (欢迎) public displays of affection, kiss or hug anyone in public, EVEN
(即使是你的爱人) your loved ones, say SORRY (道歉) as soon as possible tos eyes while talking. As a conservative country, and no one can touch it.ALTHOUGH (虽然) Indian people&#39. Is eyes are big and considered the most beautiful in Asia. So, this does not mean that Indian people are not honest.Another custom that you should PAY ATTENTION TO (注意) is that men shouldn&#39. However, whatever you do. According to Indian culture答案
提问者评价
太给力了,你的回答完美地解决了我的问题,非常感谢!
其他类似问题
为您推荐:
完形填空的相关知识
其他1条回答
请采纳,谢谢
还有一点~
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁请问一氧化碳能和氧气反应吗?求解,谢谢了_化学吧_百度贴吧
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&签到排名:今日本吧第个签到,本吧因你更精彩,明天继续来努力!
本吧签到人数:0成为超级会员,使用一键签到本月漏签0次!成为超级会员,赠送8张补签卡连续签到:天&&累计签到:天超级会员单次开通12个月以上,赠送连续签到卡3张
关注:396,494贴子:
请问一氧化碳能和氧气反应吗?求解,谢谢了收藏
请问一氧化碳能和氧气反应吗?求解,谢谢了
能。。。点燃
2CO+O2==点燃==2CO2建议LZ多看书
2CO+O2=点燃=2CO2
What can I say……
......多看看书吧
当然可以了。。。。。生成二氧化碳。。。。
登录百度帐号推荐应用
为兴趣而生,贴吧更懂你。或}

我要回帖

更多关于 matlab求解方程 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信