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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何使我的 if 語句再次運(yùn)行,就像 if-else 語句運(yùn)行一樣?

如何使我的 if 語句再次運(yùn)行,就像 if-else 語句運(yùn)行一樣?

守著一只汪 2023-09-06 16:03:38
目前,如果有人輸入超出范圍的日期,則會(huì)導(dǎo)致else語句運(yùn)行,這一切都很好,但我希望if-else語句運(yùn)行時(shí),它會(huì)重新運(yùn)行if語句。我真的不知道我應(yīng)該做什么,所以任何幫助將不勝感激!import java.util.Scanner;public class Horoscope {    public Horoscope() {        Scanner sc = new Scanner(System.in);        String output = "Please enter a valid date";        int month;        int day;        System.out.println("What is your month of birth?");        month = sc.nextInt();        System.out.println("What is your day of birth?");        day = sc.nextInt();        if((month == 3 && day >= 20 && day <= 31) || (month == 4 && day >= 1 && day <= 19)) {            System.out.println("You are an Aries");        }        else if((month == 4 && day >= 20 && day <= 30) || (month == 5 && day >= 1 && day <= 20)) {            System.out.println("You are a Taurus");        }        else if((month == 5 && day >= 21 && day <= 31) || (month == 6 && day >= 1 && day <= 20)) {            System.out.println("You are a Gemini");        }        else if((month == 6 && day >= 21 && day <= 30) || (month == 7 && day >= 1 && day <= 22)) {            System.out.println("You are a Cancer");        }        else if((month == 7 && day >= 23 && day <= 31) || (month == 8 && day >= 1 && day <= 22)) {            System.out.println("You are a Leo");        }        else if((month == 8 && day >= 23 && day <= 31) || (month == 9 && day >= 1 && day <= 22)) {            System.out.println("You are a Virgo");        }        else if((month == 9 && day >= 23 && day <= 30) || (month == 10 && day >= 1 && day <= 22)) {            System.out.println("You are a Libra");        }        else if((month == 10 && day >= 23 && day <= 30) || (month == 11 && day >= 1 && day <= 21)) {            System.out.println("You are a Scorpio");        }        else if((month == 11 && day >= 22 && day <= 31) || (month == 12 && day >= 1 && day <= 21)) {            System.out.println("You are a Sagittarius");        }        }    }}
查看完整描述

2 回答

?
BIG陽

TA貢獻(xiàn)1859條經(jīng)驗(yàn) 獲得超6個(gè)贊

import java.util.Scanner;


public class test {

    public test() {

        Scanner sc = new Scanner(System.in);

        String output = "Please enter a valid date";

        int month;

        int day;

        int k = 0;

// you can use do while loop. write some flag logic like I created k variable and it will be checked in while block

        do {

            System.out.println("What is your month of birth?");

            month = sc.nextInt();

            System.out.println("What is your day of birth?");

            day = sc.nextInt();


            if ((month == 3 && day >= 20 && day <= 31) || (month == 4 && day >= 1 && day <= 19)) {

                System.out.println("You are an Aries");

            } else if ((month == 4 && day >= 20 && day <= 30) || (month == 5 && day >= 1 && day <= 20)) {

                System.out.println("You are a Taurus");

            } else if ((month == 5 && day >= 21 && day <= 31) || (month == 6 && day >= 1 && day <= 20)) {

                System.out.println("You are a Gemini");

            } else if ((month == 6 && day >= 21 && day <= 30) || (month == 7 && day >= 1 && day <= 22)) {

                System.out.println("You are a Cancer");

            } else if ((month == 7 && day >= 23 && day <= 31) || (month == 8 && day >= 1 && day <= 22)) {

                System.out.println("You are a Leo");

            } else if ((month == 8 && day >= 23 && day <= 31) || (month == 9 && day >= 1 && day <= 22)) {

                System.out.println("You are a Virgo");

            } else if ((month == 9 && day >= 23 && day <= 30) || (month == 10 && day >= 1 && day <= 22)) {

                System.out.println("You are a Libra");

            } else if ((month == 10 && day >= 23 && day <= 30) || (month == 11 && day >= 1 && day <= 21)) {

                System.out.println("You are a Scorpio");

            } else if ((month == 11 && day >= 22 && day <= 31) || (month == 12 && day >= 1 && day <= 21)) {

                System.out.println("You are a Sagittarius");

            } else if ((month == 12 && day >= 22 && day <= 31) || (month == 1 && day >= 1 && day <= 19)) {

                System.out.println("You are a Capricorn");

            } else if ((month == 1 && day >= 20 && day <= 31) || (month == 2 && day >= 1 && day <= 18)) {

                System.out.println("You are an Aquarius");

            } else if ((month == 2 && day >= 19 && day <= 29) || (month == 3 && day >= 1 && day <= 20)) {

                System.out.println("You are a Pisces");

            } else {

                System.out.println(output);

                k = 1;

            }

        } while (k == 1);


    }

}


查看完整回答
反對(duì) 回復(fù) 2023-09-06
?
炎炎設(shè)計(jì)

TA貢獻(xiàn)1808條經(jīng)驗(yàn) 獲得超4個(gè)贊

解決了!我創(chuàng)建了一個(gè)名為 k 的 int 并將其設(shè)置為 1,并在它等于 1 時(shí)運(yùn)行 do,如果它產(chǎn)生 true if 語句,則返回 0 并結(jié)束代碼。



查看完整回答
反對(duì) 回復(fù) 2023-09-06
  • 2 回答
  • 0 關(guān)注
  • 125 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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