File size: 1,561 Bytes
ae81448
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""
Also in Java, the operator % can be used to return the remainder of a division calculation. 

For example, the operator works like this:
int remainder = 5 % 2;
// prints 1, because 5 / 2 == 2, remains 1.
System.out.println(remainder);

The same operator can be used to conveniently test whether a number is even: 
if the remainder of the division by two is one, the number is odd.



Write a program that asks the user for an integer and then prints the information whether the number is odd or even, as shown in the example output below. Thus, below is shown the execution of the program in duplicate:


Example output 1:
Give a number: 8
Number 8 is even


Example output 2:
Give a number: 3
Number 3 is odd

"""



import java.util.Random;
import java.util.Scanner;



public class Test{
    public static void main(String[] args){
        final Random r = new Random();
        
        Scanner reader = new Scanner(System.in);
        System.out.print("Give a number: ");
        int num = Integer.valueOf(reader.nextLine());

        int remainder = num % 2;
        if (remainder == 1) {
          System.out.println("Number "+num+" is odd");
        }
        else {
          System.out.println("Number "+num+" is even");
        }

        
    }
}



'''Testing with input 8
Give a number: 8
Number 8 is even

Testing with input 3
Give a number: 3
Number 3 is odd

Testing with input 11
Give a number: 11
Number 11 is odd

Testing with input 6
Give a number: 6
Number 6 is even

Testing with input 927
Give a number: 927
Number 927 is odd



'''