In class bordom

This post was written by Brandon on September 16, 2009
Posted Under: Java

So today in my Java class, when everyone was learning how to do their Hello world "programs" I just coded some random thing that takes input until a certain string is entered, and counts the vowels.

I will probably be posting a whole bunch of random codes up as the weeks go on and I am sitting in class.

 
import java.util.*;
public class Sept16{
  public static void main(String[] args){
    Scanner input = new Scanner(System.in);
    String stringtest;
    String exitstring = "end";
    String fullString = "";
    int vowels,substart,subend;
    do {
    stringtest = input.next();
    if (!stringtest.equals(exitstring)){
    fullString = fullString + stringtest;
    }
    }while(!stringtest.equals(exitstring));
    int strlength = fullString.length();
    System.out.println(strlength);
    System.out.println(fullString);
 
    substart = 0;
    subend = 1;
    vowels = 0;
    for (int i = 0; i <=(strlength-1); i++) {
      if (fullString.substring(substart,subend).equals("a")) {
        vowels += 1;
      } else if (fullString.substring(substart,subend).equals("e")) {
        vowels += 1;
      } else if (fullString.substring(substart,subend).equals("i")) {
        vowels += 1;
      } else if (fullString.substring(substart,subend).equals("o")) {
        vowels += 1;
      } else if (fullString.substring(substart,subend).equals("u")) {
        vowels += 1;
      }
      substart += 1;
      subend += 1;
    }
    System.out.println("Vowels: " + vowels);
  }
}
 

Reader Comments

cool!
we learn C# at my school, it’s pretty much the same with different functions and a tweaked syntax..
the best I ever did was printing a “star of David” in blue and white (quite easy, though not as easy as it sounds).

#1 
Written By Yuval on November 8th, 2009 @ 4:44 pm

Not too sure what you mean Yuval, maybe you have a demo?

#2 
Written By Brandon on November 8th, 2009 @ 9:09 pm

Looks cool!

#3 
Written By Brandon on November 9th, 2009 @ 4:27 pm

Trackbacks

  1. The star of david « Irrelevancy  on November 9th, 2009 @ 10:36 am

Add a Comment

required, use real name
required, will not be published
optional, your blog address