第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

異常處理:

輸入的是否是整數(shù)可以使用判斷結(jié)構(gòu)嗎?

正在回答

3 回答

Scanner input=new Scanner(System.in);

if(input.hasNext()) {

???? try{

???????? Integer.valueOf(input.nextLine());#轉(zhuǎn)為int成功的話,就是整數(shù),轉(zhuǎn)化失敗就不是整數(shù)

???????? System.out.println("你輸入的是整數(shù)");

???? }

????catch(Exception e){

???? ???? System.out.println("你輸入的不是整數(shù)");

???? }

}


0 回復(fù) 有任何疑惑可以回復(fù)我~


/**

?* 學(xué)習(xí)異常

?* @author zhuzg

?*

?*/

public class TestException {

public static void main(String[] args) {

/*try {

int i = 100/0;

}catch(java.lang.ArithmeticException e){

e.printStackTrace();

}

int[] iArray = new int[10];

iArray[1] = 10;*/

//iArray[1] = new Object();

System.out.println("TestException is " + TestException());

System.out.println("TestException2 is " + TestException2());

System.out.println("TestException3 is " + TestException3());

System.out.println(" testException5 ? result is " + testException5() );?

MyCls mc = new MyCls();

?

}

/**

*? ?問返回多少? ?4

* @return

*/

public static int? TestException() {

// TODO Auto-generated constructor stub

try {

int i = 100/0;

return 1;

}catch(java.lang.ArithmeticException e){

e.printStackTrace();

return 2;

}finally{

return 4;

}

//return 3;

}

/**

*? ?問返回多少? 2

* @return

*/

public static int? TestException2() {

// TODO Auto-generated constructor stub

try {

int i = 100/0;

return 1;

}catch(java.lang.ArithmeticException e){

e.printStackTrace();

return 2;

}

//return 3;

}

/**

* 返回內(nèi)容

* @return

*/

public static int? TestException3() {

// TODO Auto-generated constructor stub

try {

int i = 100/0;

return 1;

}catch(java.lang.ArithmeticException e){

//e.printStackTrace();

int j= 100/0;

return 2;

}

//return 3;

}

public static int? TestException4() {

// TODO Auto-generated constructor stub

? ? // 錯(cuò)誤的代碼寫法? 前邊不能包括后邊

/* try {

int i = 100/0;

return 1;

}catch(Exception e) {

}catch(ArithmeticException e){

//e.printStackTrace();

int j= 100/0;

return 2;

}*/

/**

*? 后邊可以包含前邊

*/

try {

int i = 100/0;

return 1;

}catch(ArithmeticException e) {

return 100;

}catch(Exception e){

//e.printStackTrace();

int j= 100/0;

return 2;

}

//return 3;

}

/**

* 不會(huì)有任何返回會(huì)

* @return

*/

public static int testException5() {

try {

return 100/0;

}catch(Exception e) {

System.exit(10);

return 10;

}finally {

return 20;

}

}

public static int testException6() {

try {

return 100/0;

}catch(Exception e) {

// 得到的是錯(cuò)誤詳細(xì)信息

// e.getMessage()

// 打印棧的調(diào)用順序圖

// e.printStackTrace();

//? 既然是棧? 一定在同一個(gè)線程? ? ?一個(gè)線程不可能打印另外一個(gè)線程中異常內(nèi)容。

// 一個(gè)線程中的函數(shù)絕對(duì)不可能調(diào)用到其他線程的函數(shù)

return 10;

}finally {

return 20;

}

}


}


/**

?* 構(gòu)造器也需要處理異常

?* @author zhuzg

?*

?*/

class MyCls{

public MyCls() {

int i = 100/0;

}

}


0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

學(xué)霸985

評(píng)論時(shí)可以選擇代碼框輸入代碼的,,,
2019-02-22 回復(fù) 有任何疑惑可以回復(fù)我~

你可以使用instanceof關(guān)鍵字來判斷是不是整數(shù),例如:https://img1.sycdn.imooc.com//5b32d42c00017df606300299.jpg




0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消
Java入門第三季
  • 參與學(xué)習(xí)       409775    人
  • 解答問題       4546    個(gè)

Java中你必須懂得常用技能,不容錯(cuò)過的精彩,快來加入吧

進(jìn)入課程
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)