Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

Members: Tadem, Marjon & Estrebella, Harvy Date: 10/13/22

Course & Section: BSIT-2C


import java.util.Scanner;
public class Array{
public static void main (String[] args){
Scanner user = new Scanner(System.in);
int arr[] = new int[10];
int sum = 0;
String ulet = " ";
int i = 0,j = 0,counter = 0;
boolean prime = true;

System.out.println("Applying Arrays");
System.out.println("Prepared by: Estrebella Harvy & Marjon Tadem\n");
do{
for(i = 0; i<arr.length; i++){
System.out.print("Enter integer ["+i+ "]: ");
arr[i] = user.nextInt();
}
System.out.print("List of prime numbers: ");
for (i = 0; i<arr.length; i++){
prime = true;
if (prime==true){
counter++;
}
if (arr[i]==1 || arr[i]==0){
prime = false;
counter--;
}
else{
for(j = 2; j<=arr[i]/2; j++){
if (arr[i]%j == 0){
counter--;
prime = false;
break;
}
}
}
if (prime==true){
System.out.print(" "+arr[i]);
sum += arr[i];
}
}
System.out.println("\nCount of prime numbers: "+counter);
System.out.println("Sum of all prime number: "+sum);
System.out.print("\n Do you want to try again? [Y/N]: ");
ulet = user.next();
counter = 0;
sum=0;
}while (ulet.equalsIgnoreCase("Y"));

}
}

You might also like