-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogram4.java
More file actions
36 lines (32 loc) · 868 Bytes
/
program4.java
File metadata and controls
36 lines (32 loc) · 868 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package lab4;
import java.util.InputMismatchException;
import java.util.Scanner;
public class program4 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int num=-1;
boolean isodd=false;
do {
System.out.println("Please enter a number or enter ‘-1’ if you want to quit" );
Scanner sc=new Scanner(System.in);
try
{
num=sc.nextInt();
}catch(InputMismatchException ie) {
System.out.println("You must enter an integer");
}
isodd=checkoddnum(num);
if(isodd)
{
System.out.println("You have entered an odd number");
}
else
{
System.out.println("You have entered an even number");
}
}while(num!=-1);
}
private static boolean checkoddnum(int num) {
return (num%2)!=0;
}
}