0

Gotham City Java

Whenever I test the code it works with different numbers, but it doesn't pass the test when I put it in. Can someone point me in the right direction of what I'm doing wrong? int criminals = 1; if ( criminals < 5 ) { System.out.println("I got this!"); } else if( criminals <= 10) { System.out.println("Help me Batman"); } else if( criminals > 10) { System.out.println("Good Luck out there!"); }

18th Feb 2020, 11:32 PM
Josh Ely
Josh Ely - avatar
8 Answers
+ 4
how are you getting the input? if that's the whole code. you need: at the very top import java.util.Scanner ; Scanner inp = new Scanner(System.in) ; int x = inp.nextInt(); remove: int criminals = x; the rest is ok.
18th Feb 2020, 11:42 PM
Bahhaāµ£
Bahhaāµ£ - avatar
+ 3
Don't forget to import the scanner library: import java.util.Scanner;
18th Feb 2020, 11:56 PM
Cmurio
Cmurio - avatar
+ 3
En la segunda condicional te falta agregar la condicion que sea mayor de 5. For example: criminals>=5 && criminals<=10
19th Feb 2020, 12:01 AM
Cmurio
Cmurio - avatar
+ 3
Ok. So I think I'm getting ahead of myself with this one. I haven't learned about scanners yet.
19th Feb 2020, 12:02 AM
Josh Ely
Josh Ely - avatar
0
Sorry. I edited it to show how I actually had it in the system. I copy pasted the wrong one.
18th Feb 2020, 11:46 PM
Josh Ely
Josh Ely - avatar
0
Increment that criminals variable
19th Feb 2020, 6:52 PM
suvam kumar sahoo
suvam kumar sahoo - avatar
0
in the first else if statement, you should check if criminals is greater than or equal to (>=) and less than 10. So basically it is: criminals >= 5 && criminals < 10
5th May 2020, 1:46 PM
Epsilon ļø»ā•¦ĢµĢµĶ‡ĢæĢæĢæĢæā•¤ā”€ā”€
Epsilon ļø»ā•¦ĢµĢµĶ‡ĢæĢæĢæĢæā•¤ā”€ā”€ - avatar
0
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int criminalCount = sc.nextInt(); if(criminalCount < 5){ System.out.println("I got this!"); } else if(criminalCount>=5 && criminalCount<=10){ System.out.println("Help me Batman"); } else{ System.out.println("Good Luck out there!"); } } }
24th Jun 2021, 1:37 PM
DIPTIRANI SAHU