Variables Intro
The Code
The code for the second class of Java is as follows:
public class Countdown { /** * @param args the command line arguments */ public static void main(String[] args) throws InterruptedException { //Countdown program //To demonstrate loops and how to pause a program. // for loop starting at 10 and ending at 0 for (int i = 10; i>-1; i--) { System.out.print("Hello"); System.out.println(i); sleep(1000); // Sets the program to sleep - this is why main() heading now // includes "throws InterruptedException" } }// End of main }// End of class ============Vowel Counter ======================== public class VowelCounter { // The majority of the code needed for a vowel counter // algorithm /** * @param args the command line arguments */ public static void main(String[] args) { // Program to count the vowels and consonants in a word. // Students will use this and incorporate checks for other characters. int x = 0 ; int no_vowels = 0, no_consonants = 0; String fullname = " "; Scanner o = new Scanner(System.in); System.out.println("Type your name ==>"); fullname = o.nextLine().toUpperCase(); // Use a do...while to loop through the word do { Character check = fullname.charAt(x); // if ...else construct to evaluate letter if (check == 'A') { no_vowels++; } else if (check == 'E') { no_vowels++; } else if (check == 'I') { no_vowels++; } else if (check == 'O') { no_vowels++; } else if (check == 'U') { no_vowels++; } else { no_consonants++; //Assuming for now, only letters are inserted // so if not a vowel, letter must be a consonant } x++; } while (x< fullname.length()); System.out.println("Your name contains "); System.out.println(no_vowels+" vowels and " +no_consonants+ " consonants"); } // End of main } // End of class