+ 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"); } } }
3 Answers
+ 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")
+ 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);}
}
}
0
You're welcome! I'm glad it worked