Question #273247

Write a complete Java program that do the following:

a.   Read your student’s ID number, store it in an array named myStudentNO and print it.

b.   find the number of even and odd integers in myStudentNO array


Expert's answer

Source code

import java.util.Scanner;
public class Main
{
	public static void main(String[] args) {
	    int n;
	    System.out.print("Enter the length of your student ID No:");
	    Scanner in=new Scanner(System.in);
	    n=in.nextInt();
		System.out.println("Enter your student's ID NO: ");
		int [] myStudentNO=new int[n];
		for(int i=0;i<n;i++){
		    myStudentNO[i]=in.nextInt();
		}
		int countEven=0;
		int countOdd=0;
		for(int i=0;i<n;i++){
		    if (myStudentNO[i]%2==0){
		        countEven++;
		    }
		    else{
		        countOdd++;
		    }
		}
		System.out.print("Your student's ID NO: ");
		for(int i=0;i<n;i++){
		    System.out.print(myStudentNO[i]);
		}
		System.out.println("\nNumber of even numbers: "+countEven);
		System.out.println("Number of odd numbers: "+countOdd);
	}
}


Output





Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS