-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQ1.java
29 lines (26 loc) · 825 Bytes
/
Q1.java
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
package WIX1002_1_2020;
import java.util.Scanner;
public class Q1 {
public static void main(String[] args) {
System.out.println("This program changes all the odd numbers in the array into even numbers.");
Scanner s = new Scanner(System.in);
int size = 5;
int[] num = new int[size];
System.out.print("Enter five integer numbers :");
for (int i = 0; i < size; i++) {
num[i] = s.nextInt();
}
convert(num);
System.out.print("The numbers are :");
for (int i = 0; i < size; i++) {
System.out.print(num[i] + " ");
}
System.out.println();
}
public static void convert(int[] a){
for (int i = 0; i < a.length; i++) {
if(a[i] % 2 == 1)
a[i] += 1;
}
}
}