Quick Links to Application questions (with solutions)!

C++.

Java.

Wednesday, February 17, 2010

Numbers - If statement (with user input) code

import java.util.Scanner;
class bananas
{
public static void main(String args[])
{
Scanner eggs = new Scanner(System.in);
System.out.println("Enter an integer between 10 and 100 or -10 and -100: ");
int x;
x = eggs.nextInt();
if (x > 10 && x <100 || x < -10 && x > -100)
if (x > 10 && x <100)
System.out.println("The number you entered is between 10 and 100.");
else
System.out.println("The number you entered is between -10 and -100.");
else if (x < 10 && x > -10)
System.out.println("The number you entered is beteen -10 and 10. It's not between 10 and 100 or -10 and -100.");
else
System.out.println("The number you entered is not between 10 and 100 or -10 and -100.");
}
}

No comments:

Post a Comment