Assignemnt #86
Code
///colin hinton
///5th period
///Letter
///12/4/2015
import java.util.Scanner;
public class Letter
{
public static void main( String[] args )
{
Scanner kb = new Scanner(System.in);
System.out.print("What is your message? ");
String message = kb.nextLine();
System.out.println("\nYour message is " + message.length() + " characters long.");
System.out.println("The first character is at position 0 and is '" + message.charAt(0) + "'.");
int lastpos = message.length() - 1;
System.out.println("The last character is at position " + lastpos + " and is '" + message.charAt(lastpos) + "'.");
System.out.println("\nHere are all the characters, one at a time:\n");
for ( int i=0; i < message.length(); i++ )
//i must be less than message length and not equal to because we took one away from meggage. So therefore it can never truly equal the last number because we are supposed to be one behind it.
{
System.out.println("\t" + i + " - '" + message.charAt(i) + "'");
}
int a_count = 0;
for ( int i=0; i < message.length(); i++ )
{
char letter = message.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 " + a_count + " vowels. Isn't that interesting?");
}
}
// box has a length of three, however the position of the x would be two because we use a zero to start off.
//The loop repeats while I is less than message length because we begin at zero so for the same number of characters to appear we need there to be one less than the total.
Picture of the output