當前位置:編程學習大全網 - 編程軟體 - JAVA程序while loop出現無限循環求專家指導。

JAVA程序while loop出現無限循環求專家指導。

很簡單。妳的意思是當它不是壹個數字,而是妳的System.out.println("請輸入壹個數字!") )輸出字符串;會作為妳的input.next()的內容,所以if (input.hasNextInt())不會成立,所以壹直循環打印。

根據妳的想法,我為妳改進了它:

包裝文本;

導入Java . util . scanner;

公共類文本2 {

/**

* @param args

*/

公共靜態void main(String[] args) {

// TODO自動生成的方法存根

掃描儀輸入=新掃描儀(system . in);

System.out.print("行號:");

布爾ischoice = true

int a = 0;

while (ischoice) {

string a 1 = input . next();

嘗試{

a = integer . parse int(a 1);

ischoice = false

}

捕捉(例外e)

{System.out.println("請輸入壹個數字!");}

}

for(int I = a;我& gt0;我- ) {

for(int j = I;j & gt0;j - ) {

system . out . print(" * ");

}

system . out . println(" ");

}

}

}

  • 上一篇:plc 簡單編程問題
  • 下一篇:大學本科的數字媒體技術要學哪些軟件
  • copyright 2024編程學習大全網