+ 1

Question about Boolean Operators (Java) Part 2

This is another boolean program I cannot run. Appreciate any help! import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Name a letter that is more than zero but less than 100"); int number = inputInt(); if (number > 0 && number < 100) { System.out.println("True!"); if else !(number > 0 && number < 100); System.out.println("Sorry false"); } } }

26th May 2019, 11:51 PM
Markie Alicia
Markie Alicia - avatar
3 ответов
+ 3
As in your other question, the correct method for getting an int is input.nextInt(); Also you have to close the "if" brackets before the "else if" (you have to write "else if" (or just "else" if you have no condition),not "if else")
26th May 2019, 11:55 PM
Andres0b0100
Andres0b0100 - avatar
+ 2
Thank You Andres! import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Name a number that is more than zero but less than 100"); int number = input.nextInt(); if (number > 0 && number < 100) { System.out.println("True!" + number); } else if ( !(number > 0 && number < 100)) { System.out.println("Sorry false" + number);} } }
27th May 2019, 12:42 AM
Markie Alicia
Markie Alicia - avatar
0
You're welcome! I'm glad it worked
27th May 2019, 12:47 AM
Andres0b0100
Andres0b0100 - avatar