Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package javaapplication328;
- import java.util.*;
- /**
- *
- * @author Medina
- */
- public class JavaApplication328 {
- //
- //
- public static void main(String[] args) {
- Scanner scan=new Scanner (System.in);
- //counter variables and values here
- int ctr = 0;
- int i;
- System.out.println("Menu \n[1] count and display odd\n[2] count and display even\n[3] divisible by 3\n[4] vowels");
- System.out.print("Choose a number: ");
- int menu = scan.nextInt();
- System.out.println("-00000000000000000000000000000000000000000000000000-");
- System.out.println(" ");
- if (menu==1){
- //cout display odd
- System.out.println("Display odd array");
- int[]arr=new int[5];
- for(i=0;i<5;i++)
- {System.out.println("Input arr["+i+"]: ");
- arr[i]=scan.nextInt();}
- System.out.println(" ");
- for (i=0;i<5;i++){
- if (arr[i]%2!=0){System.out.print("arr["+i+"]: ");
- System.out.println(arr[i]);}
- }
- }
- else if (menu==2){
- //cout display even
- System.out.println("Display even array");
- int[]arr=new int[5];
- for(i=0;i<5;i++)
- {System.out.println("Input arr["+i+"]: ");
- arr[i]=scan.nextInt();}
- System.out.println(" ");
- for (i=0;i<5;i++){
- if (arr[i]%2==0){System.out.print("arr["+i+"]: ");
- System.out.println(arr[i]);}
- }
- }
- else if (menu==3){
- //cout divisible by 3
- System.out.println("Display divisible by 3 array");
- int[]arr=new int[5];
- for(i=0;i<5;i++)
- {System.out.println("Input arr["+i+"]: ");
- arr[i]=scan.nextInt();}
- System.out.println(" ");
- for (i=0;i<5;i++){
- if (arr[i]%3==0){System.out.print("arr["+i+"]: ");
- System.out.println(arr[i]);}
- }
- }
- else if (menu==4){
- //cout vowels
- System.out.print("Input character string: ");
- String str = scan.next();
- str=str.toLowerCase();
- char c = ' ';
- int vowel = 0;
- for(i=0;i<str.length();i++)
- {c=str.charAt(i);
- if (c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
- {vowel++;}
- }
- System.out.print("There are: "+vowel+" vowel/s");
- }
- else{
- System.out.println("Please choose a number");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement