0

Could someone help me solve why the result says i need an ')' ?

import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner read = new Scanner(System.in); boolean isSuspended = read.nextBoolean(); int ourScore = read.nextInt(); int theirScore = read.nextInt(); // your code goes here if(isSuspended is false) { if(ourScore = theirScore) System.out.println("Draw"); if(ourScore < theirScore) System.out.println("Lost"); if(ourScore > theirScore) System.out.println ("Won"); }else{ if(isSuspended is true ) System.out.println("Suspended"); } } } ........................................................................ Im trying to get this code to work in the nested if/else practice. I think ive set it up at least conceptually well, but the program when run says i need a parenthesis. Does anybody see whats wrong? Thanks

5th Sep 2021, 1:00 PM
Michael Carr
6 odpowiedzi
+ 3
Michael Carr you dont need else after every if
5th Sep 2021, 2:03 PM
Patel
+ 3
Michael Carr 2 general mistakes 1 - (isSuspended is false) not a write syntax, it should be (isSuspended == false) 2 - single equal (=) is used for assignment not for comparison, double equal (==) is used for comparison Now coming on solution: you can do like this: if (isSuspended) { //Print Suspended } else { //rest condition will be inside this part } As isSuspended is a type of boolean so it is not necessary to compare with true or false. You can simply write: if (true) or if(!false)
5th Sep 2021, 2:32 PM
A͢J
A͢J - avatar
+ 2
For boolean there are two possible values true and false So u don't need using if inside else import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner read = new Scanner(System.in); boolean isSuspended = read.nextBoolean(); int ourScore = read.nextInt(); int theirScore = read.nextInt(); // your code goes here if(isSuspended ==false) { if(ourScore == theirScore) System.out.println("Draw"); if(ourScore < theirScore) System.out.println("Lost"); if(ourScore > theirScore) System.out.println ("Won"); }else{ System.out.println("Suspended"); } }
5th Sep 2021, 1:05 PM
Pariket Thakur
Pariket Thakur - avatar
0
Do i need an else after every if?
5th Sep 2021, 1:01 PM
Michael Carr
0
Thank you!
5th Sep 2021, 1:07 PM
Michael Carr