Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!

T pn

Greenhorn
+ Follow
since Nov 07, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by T pn

Originally posted by Rory Scott:
Oops, forgot the code



class Vowel
{
public static void main(String[] args)throws Exception
{
int counter=0;
int length;
char letter;
String[] name = {"Rory", "Ana", "Carla", "Mom", "Dad"};
sortString(name);
for(int i=0; i<5;i++)
{
length = name[i].length();
for(int j=0; j<length;j++)
{
letter=name[i].charAt(j);
if(letter=='a'|| letter=='e'||letter== 'i'||letter== 'o'||letter=='u'||letter=='A'||letter=='E'||letter=='I'||letter=='O'||letter=='U')
counter++;
}
System.out.println("There were "+counter+" vowels.");
}
}
public static void sortString(String[] args)
{
length = 4;
for(int i=0;i<length;i++)
{
if(name[i].compareTo(name[i+1])>0)
{
char temp = name[i];
name[i] = name[i +1];
name[i+1]=temp;
}
}
for(int i=0; i<5;i++)
System.out.print(name[i]+" ");
}
}



You should modify sortString method following:


public static void sortString(String[] name)
{

for(int i=0;i<name.length;i++)


for(int j=i+1;j<name.length;j++)

{
if(name[i].compareTo(name[j])>0)
{
String temp = name[i];
name[i] = name[j];
name[j]=temp;
}
}

for(int i=0; i<name.length;i++)
System.out.print(name[i]+" ");
}

Have funs
19 years ago