我不知道我是否正确使用了conditinal语句(if和else)。 它说Kuiz.java:29:错误:'else'没有'if' 和第40行相同
System.out.println("Fillojme me kuizin");
System.out.println();
System.out.println("P1) Cili eshte kryeqyteti i Frances? \t\n 1)Londra \t\n 2)Parisi \t\n 3)Roma");
int a = scan.Int();
if(a == 1)
{
System.out.println("E sakte! ");
}
else
{
System.out.println("E pasakte, Parisi eshte pergjigja e sakte");
}
System.out.println("P2)A mund te ruajme vleren \"dera\" ne nje variabel te tipit int? \t\n 1)Po \t\n 2)Jo");
int b = scan.nextInt();
if(b == 2 );
{
System.out.println("E Sakte!");
}
else
{
System.out.println("E pasakte, dera eshte nje String kurse ne variabel mund te ruajme vetem numra te plote");
}
System.out.println("P3)Cili eshte rezultati i 6+9/3 \t\n 1)5 \t\n 2)5 \t\n 3)15/3");
int c = scan.nextInt();
if(c == 2);
{
System.out.println("E sakte!");
}
else
{
System.out.println("Pergjigja e pasakte");
}
}
}
答案 0 :(得分:5)
您需要在if
条件后删除分号。
语法是
if (condition)
{
do something
} else {
do something else
}
如果添加分号则表示
if (condition)
; // i.e. do nothing
{
do something // this is divorced from the if statement
}
else // this is an error because it's not linked with an if statement