+ 1

Logical statements.

I am missing something, but I don't know what exactly, there are no errors in the code itself, but the are no results in the input. 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 % 10==0 && number % 9==0) { System.out.println("You won $200.");} if (number % 4==0 || number % 6==0) { System.out.println("You won $50.");} if (number == 0) {System.out.println("Try again."); } } }

5th Aug 2021, 7:24 PM
Андрей Хоменко
Андрей Хоменко - avatar
4 Antworten
+ 3
Your code works fine. You don't have any conditions set to display anything that doesn't fall within the other conditions. :::INPUT:::: 90 :::OUTPUT::: You won $200. You won $50. Just update your code to account for condition that isn't equal to the winning ones. Example: https://code.sololearn.com/cqRXfYye3hEm import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner read = new Scanner(System.in); int number = read.nextInt(); if (number % 10==0 && number % 9==0) { System.out.println("You won $200."); } else if (number % 4==0 || number % 6==0) { System.out.println("You won $50."); } else { System.out.println("Try again."); } } } Another example: import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner read = new Scanner(System.in); int number = read.nextInt(); int prize = 0; if (number % 10==0 && number % 9==0) { prize = 200; } else if (number % 4==0 || number % 6==0) { prize = 50; } if(prize > 0) { System.out.println("You won
quot; + prize + "!"); } else { System.out.println("Try again."); } } } :::INPUT::: 12 :::OUTPUT::: You won $50! :::INPUT::: 11 ::::OUTPUT::: Try again. :::INPUT::: 90 :::OUTPUT::: You won $200!
5th Aug 2021, 7:38 PM
Jakko Jak
Jakko Jak - avatar
+ 2
Your code gives no output if your first if statement (or any) is not executed. For that, you can use else and else if statement to handle the input even if first if statement isn't executed. Try Jakko's first example. https://code.sololearn.com/cqRXfYye3hEm
6th Aug 2021, 12:58 AM
Simba
Simba - avatar
0
Same thing with every example, there are no outputs, what am I doing wrong? import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner read = new Scanner(System.in); int number = read.nextInt(); int prize = 0; if (number % 10==0 && number % 9==0) { prize = 200; } else if (number % 4==0 || number % 6==0) { prize = 50; if(prize > 0); { System.out.println("You won
quot; + prize + "!"); } } else { System.out.println("Try again."); } } }
5th Aug 2021, 7:57 PM
Андрей Хоменко
Андрей Хоменко - avatar
0
In what you just posted back, you accidentally put the "if(prize > 0)" portion out of order and added a semi-colon to it. Just copy/paste what I posted and it'll work, then mess with it further from there as you want.
6th Aug 2021, 1:32 AM
Jakko Jak
Jakko Jak - avatar