如何继续循环java

if (anotherScanner.hasNext("t|T")) {

c = anotherScanner.next();
System.out.println("");
System.out.println("COIN TOSS SIMULATOR");
System.out.println("");
System.out.println("Enter 0 to quit. How many tosses?");

Random rand = new Random();
float tailsCount = 0;
Scanner scanMan = new Scanner(System.in);
int numero = scanMan.nextInt();

for (int j=0;j < numero;j++) {
if (numero == 0) { break; }

} else {
tailsCount++;

}
}
}

回答(4)

System.out.println("\ncontinue to inner when i is 2 and j is 2:");
for (int i = 1; i <= 3; i++) {
here4: for (int j = 1; j <= 3; j++) {
if ((i == 2) && (j == 2)) {
System.out.print("[continue to inner]");
continue here4;
}
System.out.print("[i:" + i + ",j:" + j + "]");
}
}

for (int j = 0; j < numero; j++) {
if (numero == 0) {
break;
}
...
}

if(numero !=0) {
for (int j = 0; j < numero; j++) {
...
}
}

...虽然这里写的是 if 是无关紧要的，因为 for 循环仍然会循环零次 .

if(numero !=0) {
for (int j = 0; j < numero; j++) {
...
}
System.out.println(...);
}

// Get input; play game until input is zero.
void playCoinTossGames(Scanner scanner) {
int input = promptAndGetInt(scanner);
while(input != 0) {
playOneCointossGame(input);
int input = promptAndGetInt(scanner);
}
// note two calls to get input above. This is called a
}

// Print a prompt, then scan input for an integer
int promptAndGetInt(Scanner scanner) {
System.out.println("How many tosses? (0 to exit)";
return scanner.nextInt();
}

// Toss numberOfTosses times, then report the % of heads.
void playOneCointossGame(int numberOfTosses) {
for(int i=0; i<numberOfTosses; i++) {
// Toss a coin and record result
}
System.out.println(...); // summary of results
}
{"ft_lang_label":"__label__zh","ft_lang_prob":0.76919824,"math_prob":0.9824126,"size":1470,"snap":"2022-05-2022-21","text_gpt3_token_len":852,"char_repetition_ratio":0.12755798,"word_repetition_ratio":0.0,"special_character_ratio":0.25510204,"punctuation_ratio":0.24107143,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.995645,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-01-16T19:00:24Z\",\"WARC-Record-ID\":\"<urn:uuid:4ac11a4b-b42d-4e6e-b259-6d00e307e5d9>\",\"Content-Length\":\"18167\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:d632a8c0-507f-48d8-aac3-94cb9c457f6b>\",\"WARC-Concurrent-To\":\"<urn:uuid:229c3738-7f9c-498b-b2bb-d7920c2295f4>\",\"WARC-IP-Address\":\"106.13.41.72\",\"WARC-Target-URI\":\"https://www.javaroad.cn/questions/51460\",\"WARC-Payload-Digest\":\"sha1:P6PADN34X2EEPW4Y3LIADFS7REN7HTG6\",\"WARC-Block-Digest\":\"sha1:IQW66JC77INU5OADH42DK2MFMJ5PQUVP\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-05/CC-MAIN-2022-05_segments_1642320300010.26_warc_CC-MAIN-20220116180715-20220116210715-00321.warc.gz\"}"}