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

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

無論我正確輸入,Java 都沒有運行我的掃描儀

無論我正確輸入,Java 都沒有運行我的掃描儀

慕的地6264312 2023-07-28 16:08:54
在沒有大括號的 while 中,只有緊跟在 while 后面的語句才會被執(zhí)行。在您的情況下,這意味著只有 while 之后的第一個語句將被循環(huán),即“System.out.println(myintarray[index]);”。由于“index++;” 未達到時,您的索引將具有相同的值 0,因此您的程序將始終打印數(shù)組的第一個元素。您的代碼范圍將在大括號中轉換為:while(index < 3) {    System.out.println(myintarray[index]);}index++;要執(zhí)行多個語句,請將其全部括在大括號內。while(index < 3) {    System.out.println(myintarray[index]);    index++;}
查看完整描述

2 回答

?
aluckdog

TA貢獻1847條經驗 獲得超7個贊

我確實將運算符更改為 char,現(xiàn)在它可以工作了:-


import java.util.Scanner;

class main { //Main

 public static void main(String[] args) {

    Scanner scan = new Scanner(System.in);

    int firstnumber = 0;

  int secondnumber = 0;

  char operator;


  boolean erase = true;




  while (erase) { //While Loop (main)

   System.out.println("Enter First Number");

   firstnumber = scan.nextInt();




   System.out.println("Enter Second Number");

   secondnumber = scan.nextInt();


   System.out.println("Select Operator.");

   operator = scan.next().charAt(0);

   System.out.println("For Multiplaction: Type X");

   System.out.println("For Division: Type %");

   System.out.println("For Addition: Type +");

   System.out.println("For Subtraction: Type -");


  } //While Loop (main)

 }

} //Main 

也許您的 nextLine() 不會觸發(fā),因為您已經有兩個掃描儀提示,因此它的行為是被接受的輸入。也許你應該對此進行更多調試。盡管如此,仍然scan.next();有效...嘗試使用 Oracle JDK 1.8.0_u221 在 Visual Studio Code 1.38.1 上


查看完整回答
反對 回復 2023-07-28
?
藍山帝景

TA貢獻1843條經驗 獲得超7個贊

scan.next();代替使用。


public static void main(String[] args) {

    int firstnumber;

    int secondnumber;

    String operator;

    Scanner scan = new Scanner(System.in);

    while (true) { //While Loop (main)

        System.out.println("Enter First Number");

        firstnumber = scan.nextInt();



        System.out.println("Enter Second Number");

        secondnumber = scan.nextInt();


        System.out.println("Select Operator.");

        System.out.println("For Multiplaction: Type X");

        System.out.println("For Division: Type %");

        System.out.println("For Addition: Type +");

        System.out.println("For Subtraction: Type -");

        operator = scan.next();


        System.out.println(firstnumber);

        System.out.println(secondnumber);

        System.out.println(operator);

    } //While Loop (main)

}


查看完整回答
反對 回復 2023-07-28
  • 2 回答
  • 0 關注
  • 139 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網(wǎng)微信公眾號