Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
16 views

Java Code Activity 1

Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Java Code Activity 1

Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

package arry;

import java.util.Scanner;

public class jamaay {

public static void main(String[] args) {


int[] numbs = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20};

for (int i = 0; i < numbs.length; i++) {


System.out.print(" " + numbs[i]);}

Scanner user_input = new Scanner(System.in);

System.out.println("\n\nOPTION");
System.out.println("A = Odd \nB = Even\nC = Prime");

System.out.print("\n\nPlease choose one from the given options: ");


String user_ip = user_input.nextLine();

boolean ask = true;

switch(user_ip) {
case "A":
System.out.println("Odd Numbers:");
for(int i=0; i < 20; i++){
if(numbs[i] % 2 != 0){
System.out.print(" " + numbs[i]);
}
}
break;

case "B":
System.out.println("Even Numbers:");
for(int i = 0; i < 20; i++){
if(numbs[i] % 2 == 0){
System.out.print(" " + numbs[i] );
}
}
break;

case "C":
System.out.println("Prime Numbers:");
for (int i = 2; i <= 20; i++) {
boolean isPrime = true;
for (int j = 2; j < i; j++) {
if (i % j == 0) {
isPrime = false;
break;
}
}
if (isPrime) {
System.out.print(" " + i);
}
}

break;

default:
System.out.println("Invalid Input");
}
}
}

You might also like