0

これは、みんなが私にやるように言ったことの実用的な製品です. みんなありがとう、私はこれからコードをきれいに保つように努めます。このコードは単なる練習であり、最終的には、起動時に実行されるコンピューターのロックアウト システムになるだけです。厄介な未成年者が自分のコンピューターをいじりたいのは誰ですか? この男ではありません。

import java.io.*;
import java.util.Scanner;  /
class AgeChecker
{   
    public static void main (String[] args) throws Exception  /*@Exception- thrown to allow reading
    {                                                                       of single characters*/
    char ans; //(Read from user input)
    String name;
    boolean loop = false; //To loop back after a section, add loop = true.
                          //To stop the program after a section, add loop = false.
    do
    {
    Scanner dd = new Scanner(System.in);
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));  // Needed to read the 
    BufferedReader in1 = new BufferedReader(new InputStreamReader(System.in)); // character input

    System.out.println("What is your name? "); name = dd.nextLine();
        {   

        System.out.println("Are you 14 years of age or older? (y/n) "); ans = (char)in.read();


                                    //Using if, else-if and else to make sure
            if (ans == 'y')         //I have a good grasp of what i already know
            {   
                    System.out.println("Welcome, " + name + "! Are you 21 years of age or older? (y/n) ");
                    ans = (char)in1.read();

                    if (ans == 'n')
                    {
                    System.out.println("Welcome, " + name + "!");
                    loop = false;
                    }

                    else if (ans == 'y')
                    {
                    System.out.println("Welcome, " + name + "! Would you like a drink? ");
                    loop = false;
                    }
                }   
            else if (ans == 'n')
                {   
                System.out.println("We're sorry. Only those at the age of 14 or older may access this program. ");
                loop = false;
                }   
            else 
                {
                        System.out.println("Invalid input. ");
                        loop = true;
                }
            }
        }
    }
    while (loop == true); //Put here to line up with the 'do' at the top
}

みんな助けてくれてありがとう

4

1 に答える 1

7

交換

while (fee = true);

while (fee == true);

以上:

while (fee);

fee = trueは割り当てであり、割り当てられた値 ( ) を返しますtrue

こちらも交換

else 
System.out.println("Invalid input. ");
fee = true;

else {
   System.out.println("Invalid input. ");
   fee = true;
}

(Rohitに感謝)。

コードのスペースとブロックが少ない場合 (なぜそんなに多くの?)、これらのエラーをフェッチするのが簡単になることに注意してください (あなたも含めて)。これらのコード規則は役立つ場合があります。

于 2013-01-08T20:27:55.263 に答える