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

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定

這個代碼,怎么實現(xiàn)重復(fù)輸入,條件一直報錯


import java.util.Scanner;


public class Do_while03 {


public static void main(String[] args) {

//鍵盤錄入

Scanner nc = new Scanner (System.in);

System.out.println("請輸入數(shù)字");

//x值不等于1或2時重新輸入數(shù)字

do{int x=nc.nextInt();//接收鍵盤錄入的數(shù)據(jù)

if (x==1) {System.out.println("A");

break;

}else if(x==2){System.out.println("B");

break;

}else {

System.out.println("請重新嘗試輸入____");

}while(ture)

}

}

}


正在回答

5 回答

int i = 1;

Scanner nc = new Scanner(System.in);

System.out.print("請輸入數(shù)字:");

do {

int x = nc.nextInt();

i++;

if (x == 1) {

System.out.println("A");

} else if (x == 2) {

System.out.println("B");

} else {

System.out.print("請重新嘗試輸入:");

x = nc.nextInt();

}


} while (true);

// 只能重復(fù)輸入一次,之后就要重新運(yùn)行了

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

干嘛用break呢,你都在跳出來了,還怎么進(jìn)去

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

package day_1;


import java.util.Scanner;


public class aa {


public static void main(String[] args) {

int i = 1;

Scanner nc = new Scanner (System.in);

System.out.println("請輸入數(shù)字");

do{int x=nc.nextInt();

i++;

if (x==1) {System.out.println("A");

System.out.println(i);

}else if(x==2){

System.out.println("B");

System.out.println(i);

}else {

System.out.println("請重新嘗試輸入____");

System.out.println(i);

}

}while(i+1<=4);

}

}


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

//這個是規(guī)范的寫法:

import java.util.Scanner;


public class Do_while03 {


public static void main(String[] args) {

// 鍵盤錄入

Scanner nc = new Scanner(System.in);

System.out.println("請輸入數(shù)字");

// x值不等于1或2時,實現(xiàn)重新接收鍵盤輸入的數(shù)字

do {

int x = nc.nextInt();// 接收鍵盤錄入的數(shù)據(jù)

if (x == 1) {

System.out.println("A");

break;

} else if (x == 2) {

System.out.println("B");

break;

} else {

System.out.println("請重新嘗試輸入____");

} // 此處的大括號容易被丟

} while (true);

}

}


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

import java.util.Scanner;


public class Do_while03 {


public static void main(String[] args) {

//鍵盤錄入

Scanner nc = new Scanner (System.in);

System.out.println("請輸入數(shù)字");

//x值不等于1或2時,實現(xiàn)重新接收鍵盤輸入的數(shù)字

do{int x=nc.nextInt();//接收鍵盤錄入的數(shù)據(jù)

if (x==1) {System.out.println("A");

break;

}else if(x==2){System.out.println("B");

break;

}else {

System.out.println("請重新嘗試輸入____");

}//此處的大括號容易被丟

}while(true);//單詞錯誤

}

}


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

舉報

0/150
提交
取消

這個代碼,怎么實現(xiàn)重復(fù)輸入,條件一直報錯

我要回答 關(guān)注問題
微信客服

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

幫助反饋 APP下載

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

公眾號

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