Created
March 20, 2018 13:05
-
-
Save alexzhernovyi/f9545843f842c746d00c326a3b85d5ea to your computer and use it in GitHub Desktop.
NumChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.company; | |
import java.util.Scanner; | |
public class Main { | |
public static void main(String ... args) { | |
int number; | |
int answer = 0; | |
boolean boo = true; | |
int simple; | |
Scanner scanner = new Scanner(System.in); | |
System.out.println ("Enter Your valid number please:"); // You should enter Your valid integer | |
while (!scanner.hasNextInt()){ | |
System.out.println("Enter valid number:");// When You entered NOT valid integer | |
scanner.nextLine(); | |
} | |
simple = scanner.nextInt(); | |
scanner.nextLine(); | |
do{ // this "if" statement checks whether the number is Prime or Not Prime | |
System.out.println("\n/////// MENU ///////"); | |
System.out.println("1. Yout number even or odd?"); | |
System.out.println("2. Yout number prime?"); | |
System.out.println("3. Yout number positive or negative?"); | |
if (answer > 0) { | |
System.out.println("4.Exit"); | |
} | |
do { | |
System.out.print("\n Enter Your valid number please:"); | |
while (!scanner.hasNextInt()) { | |
System.out.println("Incorrect valid number, please enter Your number again:"); | |
scanner.nextLine(); | |
} | |
number = scanner.nextInt(); | |
scanner.nextLine(); | |
} while ( number <= 0 || (boo && number > 3) || (!boo&& number > 4)); | |
if(boo) { | |
boo = false; | |
} | |
// this "if" statement checks whether the number is even or odd | |
if (number == 1){ | |
if (simple % 2 == 0){ | |
System.out.println("Your number "+ simple + " Even"); | |
}else { | |
System.out.println("Your number "+ simple + " Odd"); | |
} | |
answer++; | |
} | |
// this "if" statement checks whether the number is Prime or Not Prime | |
if (number == 2){ | |
String check = simple + " Prime"; | |
if(simple < 2 ) { | |
check = simple +" NOT Prime"; | |
} else { | |
for (int a = 2; a < simple; a++) { | |
if(simple % a == 0){ | |
check = simple +" NOT Prime"; | |
break; | |
} | |
} | |
} | |
System.out.println ("Your number: " + check); | |
answer++; | |
} | |
// this "if" statement checks whether the number is Positive, Negetive or Zero | |
if (number == 3){ | |
if(simple > 0){ | |
System.out.println("Your number "+ simple + " Positive"); | |
} else if (simple < 0){ | |
System.out.println("Your number "+ simple + " Negative"); | |
} else { | |
System.out.println("Your number "+ simple + " Zero"); | |
} | |
answer++; | |
} | |
} while( number != 4 ); // touched chapter "4.Exite" this "while" closed this program and say "Have a good day, Bye" | |
System.out.println("Have a good day, Bye"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment