+ 1

Problem in gotham city code

import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner sc = new Scanner ( System.in); System.out.println("WELCOME TO GOTHAM CITY AND YOU ARE RECRUITED AS A POLICE OFFICER, YOU NEED TO HANDLE AN ELOPEMENT") ; String A="I GOT THIS"; String B="HELP ME BATMAN"; String C="GOOD LUCK OUT THERE"; int criminal; if(criminal<5) System.out.println (A); else if(criminal>5 && criminal<10) System.out.println (B); else System.out.println (C); } }

30th Mar 2020, 4:31 PM
Arka Dey
Arka Dey - avatar
4 Answers
30th Mar 2020, 4:44 PM
Nature of me
Nature of me - avatar
+ 1
you ask for help when you have 5 to 10 opponents. so the else if statement should be: else if (criminal>=5 && criminal <=10)
30th Mar 2020, 5:11 PM
John Robotane
John Robotane - avatar
+ 1
import java.util.Scanner ; public class Program { public static void main(String[] args) { Scanner sc=new Scanner (System.in); int x=sc.nextInt(); if(x<5){ System.out.println ("I got this!");} else if(x>=5){if(x<=10){ System.out.println ("Help me Batman");} else { System.out.println ("Good Luck out there!"); } } } }
30th Mar 2020, 5:27 PM
Nature of me
Nature of me - avatar
0
import java.util.Scanner; public class Program { public static void main(String [] args) { Scanner sc = new Scanner ( System.in); String A="I got this!"; String B="Help Me Batman"; String C="Good Luck Out There!"; int criminal; criminal = sc.nextInt(); if(criminal<5) System.out.println (A); else if(criminal>=5 && criminal<10) System.out.println (B); else System.out.println (C); } } This code is failing for 5 asa input. Why??
30th Mar 2020, 5:00 PM
Arka Dey
Arka Dey - avatar