Assignemnt #86 Letter At A Time
Code
/// Name: Drew Boxold
/// Period 5
/// Program Name: LetterAtATime
/// File Name: LetterAtATime.java
/// Date Finished: 3/4/16
import java.util.Scanner;
public class LetterAtATime
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
System.out.print("\nWhat is your message? ");
String str = keyboard.nextLine();
int length = str.length() ;
System.out.println("\nYour message is " + length + " characters long.");
System.out.println("The first character is at position 0 and is '" + str.charAt(0) + "'.");
System.out.println("The last character is at position " + (length - 1) + " and is '" + str.charAt(length - 1) + "'.");
System.out.println("Here are all the characters, one letter at a time.");
for ( int i=0; i < length; i++ )
{
System.out.println("\t" + i + " - '" + str.charAt(i) + "'");
}
int a_count = 0;
for ( int i=0; i < length; i++ )
{
char letter = str.charAt(i);
if ( letter == 'a' || letter == 'A' || letter == 'e' || letter == 'E' || letter == 'i' || letter == 'I' || letter == 'o' || letter == 'O' || letter == 'u' || letter == 'U' )
{
a_count++;
}
}
System.out.println("\nYour message contains vowels " + a_count + " times. Isn't that interesting?");
}
}
Picture of the output