Advertisement
letsdoitjava

Alphabet

Jun 12th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.17 KB | None | 0 0
  1. package alphabet;
  2.  
  3. public class Alphabet {
  4.     public static void main(String[] args) {
  5.         // java program that prints letters from 'a' to 'z'
  6.         // vowels (including 'y') are identified to user, all others identified as constants
  7.  
  8.         // @ author Renee Waggoner
  9.  
  10.         // intializing
  11.         char alph = 'a';
  12.  
  13.         // go all the way through the whole alphabet
  14.         while(alph<='z')
  15.         {
  16.             // instructions for vowels in body of nested switch
  17.             switch(alph) {
  18.             case 'a':
  19.                 // identifying 'a' as a vowel, and so on for each case
  20.                 System.out.println('a' + " is a vowel");
  21.                 break;
  22.  
  23.             case 'e':              
  24.                 System.out.println('e' + " is a vowel");
  25.                 break;
  26.  
  27.             case 'i':
  28.                 System.out.println('i' + " is a vowel");
  29.                 break;
  30.  
  31.             case 'o':
  32.                 System.out.println('o' + " is a vowel");
  33.                 break;
  34.  
  35.             case 'u':
  36.                 System.out.println('u' + " is a vowel");
  37.                 break;
  38.  
  39.             case 'y':
  40.                 System.out.println('y' + " is a vowel");
  41.                 break;
  42.  
  43.                 // all other letters will be identified as constants
  44.             default:
  45.                 System.out.println(alph + " is a constant");
  46.                
  47.             }
  48.             // incrementing by one so that char doesn't get stuck in a never ending loop
  49.             alph += 1;
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement