+ 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
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
0
First show your attempt , so we can help you
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);
}
}
0
Thankx