Or Operator Challenge | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Or Operator Challenge

Hello i need help in the Challenge "lucky winner" Java Lesson 14.2 import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner read = new Scanner(System.in); int number = read.nextInt(); //your code goes here if (number%9==0 && number%10==0) { System.out.println("You Won $200"); } if(number %6==0 || number%4==0){ System.out.println("You won $50"); } else { System.out.println("Try Again"); } } } This is what i wrote but in the cases they won 200 Dollar. Both cases the 50 and 200 are true. And thats what i know cause its easy maths. But what do i have to do that it will only show "You won 200" Reminder only case 2 and 4 are right from 5

2nd Jan 2022, 2:36 PM
Sasha Krömtz
4 Answers
+ 3
Try changing the second „if” to „else if”, it will change the way the code flows since this block will be ignored if the „if” before it evaluates to true
2nd Jan 2022, 3:05 PM
Nick
+ 2
I didn’t like this challange myself because of how unspecific the requirements where: It didn’t take into account that all conditions can be true.
2nd Jan 2022, 3:12 PM
Nick
0
Thx i will go threw the earlier instructions. Maybe i missed something.
2nd Jan 2022, 3:06 PM
Sasha Krömtz
0
Thx i forget lessom 13.1 completly in germany we call it something like folishness but with a slightly different meaning
2nd Jan 2022, 3:11 PM
Sasha Krömtz