當前位置:編程學習大全網 - 源碼下載 - java怎麽返回重新運行?

java怎麽返回重新運行?

妳的程序有壹些小錯誤,我給妳改了,並且按照妳的要求在輸入錯誤的情況下,程序能夠重新運行,妳看壹下吧。輸入-1程序停止。

import java.util.*;

class Test

{

public static void main(String[]args)

{

int month=0,seat=0;

try{

Scanner s=new Scanner(System.in);

System.out.println("輸入月份:");

month =s.nextInt();

System.out.println("輸入艙位,頭等艙為1,經濟艙為2:");

seat=s.nextInt();

}catch(Exception e){

System.out.println("請輸入整數!");

}

while(seat!=-1&& month!=-1){

if(month>=4&&month<=10)

{

if(seat==1)

System.out.println("您的機票價為4500RMB");

else if(seat==2)

System.out.println("您的機票價為4000RMB");

else

System.out.println("您輸入的艙位代號有誤");

}

else if(month>0&&month<4 || month>10&&month<=12)

{

if(seat==1)

System.out.println("您的機票價為2500RMB");

else if(seat==2)

System.out.println("您的機票價為2000RMB");

else

System.out.println("您輸入的艙位代號有誤");

}else{

System.out.println("您輸入的月份有誤");

}

try{

Scanner s=new Scanner(System.in);

System.out.println("輸入月份:");

month =s.nextInt();

System.out.println("輸入艙位,頭等艙為1,經濟艙為2:");

seat=s.nextInt();

}catch(Exception e){

 System.out.println("請輸入整數!");

}

}

}

}

  • 上一篇:公認最好的網遊加速器有哪些
  • 下一篇:我的世界1.7版本有什麽新增的嗎?
  • copyright 2024編程學習大全網