You are on page 1of 2

Suleiman Yahya (A00021078)

CSC 202
Homework 3

1. Search for an array

2. class Main {
3. public static void main(String[] args) {
4.
5. int[] num = {1, 2, 3, 4, 5};
6. int toFind = 3;
7. boolean found = false;
8.
9. for (int n : num) {
10. if (n == toFind) {
11. found = true;
12. break;
13. }
14. }
15.
16. if(found)
17. System.out.println(toFind + " is found.");
18. else
19. System.out.println(toFind + " is not found.");
20. }
21. }

2. Java Program to count even and odd numbers in inputted array

import java.util.Scanner;

public class CodesCracker


{
public static void main(String[] args)
{
int[] arr = new int[10];
Scanner s = new Scanner(System.in);

System.out.print("Enter 10 Numbers for the Array: ");


for(int i=0; i<10; i++)
arr[i] = s.nextInt();

int countEven=0, countOdd=0;


for(int i=0; i<10; i++)
{
if(arr[i]%2==0)
countEven++;
else
countOdd++;
}

System.out.println("\nEven Number: " +countEven);


System.out.println("Odd Number: " +countOdd);
}
for(i=1; i<10; i++){
if(i%2==0)
evenSum=evenSum+i;
else
oddSum=oddSum+
}

You might also like