In class bordom
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); } }
Tags: java input, java vowel count




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).
Not too sure what you mean Yuval, maybe you have a demo?
Looks cool!