Advertisement
heysoul_sisypus

Menu w/ array odd,even,divisible by 3 and vowel loop counter

Jan 19th, 2020
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.55 KB | None | 0 0
  1. package javaapplication328;
  2. import java.util.*;
  3. /**
  4.  *
  5.  * @author Medina
  6.  */
  7. public class JavaApplication328 {
  8. //
  9.     //
  10.     public static void main(String[] args) {
  11.         Scanner scan=new Scanner (System.in);
  12.         //counter variables and values here
  13.         int ctr = 0;
  14.         int i;
  15.         System.out.println("Menu \n[1] count and display odd\n[2] count and display even\n[3] divisible by 3\n[4] vowels");
  16.         System.out.print("Choose a number: ");
  17.         int menu = scan.nextInt();
  18.         System.out.println("-00000000000000000000000000000000000000000000000000-");
  19.         System.out.println(" ");
  20.         if (menu==1){
  21.         //cout display odd
  22.            System.out.println("Display odd array");
  23.            int[]arr=new int[5];
  24.            for(i=0;i<5;i++)
  25.            {System.out.println("Input arr["+i+"]: ");
  26.            arr[i]=scan.nextInt();}
  27.            System.out.println(" ");
  28.            for (i=0;i<5;i++){
  29.            if (arr[i]%2!=0){System.out.print("arr["+i+"]: ");
  30.            System.out.println(arr[i]);}
  31.            }
  32.         }
  33.        
  34.         else if (menu==2){
  35.         //cout display even
  36.            System.out.println("Display even array");
  37.            int[]arr=new int[5];
  38.            for(i=0;i<5;i++)
  39.            {System.out.println("Input arr["+i+"]: ");
  40.            arr[i]=scan.nextInt();}
  41.            System.out.println(" ");
  42.            for (i=0;i<5;i++){
  43.            if (arr[i]%2==0){System.out.print("arr["+i+"]: ");
  44.            System.out.println(arr[i]);}
  45.            }  
  46.         }
  47.        
  48.         else if (menu==3){
  49.         //cout divisible by 3
  50.            System.out.println("Display divisible by 3 array");
  51.            int[]arr=new int[5];
  52.            for(i=0;i<5;i++)
  53.            {System.out.println("Input arr["+i+"]: ");
  54.            arr[i]=scan.nextInt();}
  55.            System.out.println(" ");
  56.            for (i=0;i<5;i++){
  57.            if (arr[i]%3==0){System.out.print("arr["+i+"]: ");
  58.            System.out.println(arr[i]);}
  59.            }
  60.         }
  61.      
  62.         else if (menu==4){
  63.         //cout vowels
  64.         System.out.print("Input character string: ");
  65.         String str = scan.next();
  66.         str=str.toLowerCase();
  67.         char c = ' ';
  68.         int vowel = 0;
  69.         for(i=0;i<str.length();i++)
  70.         {c=str.charAt(i);
  71.         if (c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
  72.          {vowel++;}
  73.         }
  74.         System.out.print("There are: "+vowel+" vowel/s");
  75.         }
  76.      
  77.         else{
  78.          System.out.println("Please choose a number");
  79.         }
  80.        
  81.     }
  82.    
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement