Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
ICS 102 (LAB) – Computer Programming Quiz (2) – Prepared By: Sarah Alfayez Student Name: …………………………………………………………………………………… I.D: …………………………………… Question 1: Design and implement a java program that will check if the numbers in the array are even or odd. Follow these steps to perform the desired output: 1. Define a class named even_odd 2. Declare the main method. 3. Declare an array num of type integer that contains the following elements 5, 10, 15, ……,50. (use for loop) 4. Display these elements in a single line. (use a for loop) 5. Check if the elements in the array are even or odd: If even display the number is even If odd display the number is odd. Hint: your output should look like this: 5 10 number number number number number number number number number number 15 20 25 5 is odd 10 is even 15 is odd 20 is even 25 is odd 30 is even 35 is odd 40 is even 45 is odd 50 is even 30 35 40 Page 1 45 50 ICS 102 (LAB) – Computer Programming Quiz (2) – Prepared By: Sarah Alfayez Solution: public class even_odd{ public static void main (String [] args){ int [] num = new int [10]; for(int i=0; i<num.length; i++){ num[i]= (5*i)+5; System.out.print(num[i] + " } System.out.println(); "); for(int i=0; i<num.length; i++){ if(num[i]%2==0) System.out.println("number " + num[i] +" is even"); else System.out.println("number " + num[i] +" is odd"); }} } Page 2