+ 1

help in this java program

Sara wants to become a pokemon master so she invented a strategy to choose only one type of pokemon which has very high attack power and very weak defense. i. e in a fight with this type of pokemon whoever attacks first will win. A pokemon battle goes in turns(i. e at each turn one player will attack) and Sara always goes first. Given the number of pokemon of Sara and his opponent as A and B, your task is to tell whether Sara is going to win or not. Sample Input:- 4 3 Sample Output:- 1 Explanation:- Sara's attack:- A = 4, B = 2 Opponent's attack:- A=3, B=2 Sara's attack:- A = 3, B = 1 Opponent's attack:- A=2, B=1 Sara's attack:- A = 2, B = 0 Sara win's Sample Input:- 4 6 Sample Output:- 0

6th Nov 2021, 10:58 AM
Arsalan Khan
Arsalan Khan - avatar
4 Answers
+ 1
import java.util.*; class SaraOrOpponent { public static void main () { Scanner in = new Scanner (System.in); int A=in.nextInt(),B=in.nextInt(); System.out.println((A>=B)?1:0); } } Just replace >= with > if that gives an error else the program is ok
6th Nov 2021, 1:00 PM
Adi Nath Bhawani
Adi Nath Bhawani - avatar
0
First show your attempt , so we can help you
6th Nov 2021, 11:03 AM
Sâùtôsh
Sâùtôsh - avatar
0
One more shorter attempt is import java.util.*; class SaraOrOpponent { public static void main () { Scanner in = new Scanner (System.in); System.out.println((in.nextInt()>=in.nextInt())?1:0); } }
6th Nov 2021, 1:01 PM
Adi Nath Bhawani
Adi Nath Bhawani - avatar
0
Thankx
12th Nov 2021, 10:19 AM
Arsalan Khan
Arsalan Khan - avatar