次の割り当てに問題があります。
ユーザーに映画の評価と年齢の 2 つの値を入力するよう求めるプログラムを作成します。決定構造を使用して、入力されたレーティングと年齢に基づいて、ユーザーが映画館で映画を見ることを許可するかどうかを決定します。最後に、この決定の結果をユーザーに表示します。
これが私のコードです。これを投稿する前に、NetBeans で Alt+Shift+F を実行しました。
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package age;
/**
*
* @author Jason
*/
import java.util.Scanner;
public class Age {
public static void main(String[] args) {
Scanner user_input = new Scanner(System.in);
String user_age;
System.out.print("Enter your age: ");
user_age = user_input.next();
String mrating;
System.out.print("Enter the movie rating: ");
mrating = user_input.next();
}
{
if ( user_age < 13 + mrating = G);{
System.out.print( "You are of the right age for this movie");
}
else{
System.out.print(" You are not of correct age for this movie");
}
if ( user_age >= 13 + mrating = PG13);{
System.out.print( "You are of the right age for this movie");
}
else{
System.out.print(" You are not of correct age for this movie");
}
if ( user_age >= 17 + mrating = R);{
System.out.print( "You are of the right age for this movie");
}
else{
System.out.print(" You are not of correct age for this movie");
}
}
}
Age の終了ブラケットをif
ステートメントの開始前まで移動するとします。ユーザーの年齢と評価を尋ねるディスプレイを取得できますが、プログラムは結果なしで終了します。ブラケットをそのままにしておくと、プログラムは完全にエラーになります。私はJavaが初めてで、とても混乱しています.本やウェブサイトで何時間もこれに取り組んできましたが、混乱し始めています. また、user_age
変数mrating
が使用されていないというエラーが表示されます。