Tech Blog » Home » Coders Forum » Computer Directory » Math Calculators » RSS:Directory|Forum
JAVA Source Code » Coders Community: Forum
public class PyramidStars
{
public static void main(String[] args)
{
int count = 0;
for (int width = 0; width <= 20; width++)
{
for (int alignLeft = width; alignLeft <= 40; alignLeft++)
{
System.out.print(" ");
}
for (int space = 0; space < count; space++)
{
if (space % 2 == 0)
{
System.out.print(" ");
}
else
{
System.out.print("*");
}
}
System.out.println();
count += 2;
}
}
}
/*===================================[output]==============================
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
* * * * * * * * * *
* * * * * * * * * * *
* * * * * * * * * * * *
* * * * * * * * * * * * *
* * * * * * * * * * * * * *
* * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * *
===========================================================================*/
// end of class PyramidStars
import java.util.Scanner;
public class VowelCount
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
String word = " ";
int count = 0;
int index = 0;
System.out.print( "Enter a word or sentence: " );
word = scan.nextLine();
while (index < word.length())
{
switch (word.toUpperCase().charAt(index))
{
case 'A': count++;
break;
case 'E': count++;
break;
case 'I': count++;
break;
case 'O': count++;
break;
case 'U': count++;
break;
}
index++;
}
System.out.println( "I have found " + count + " vowels." );
}
}
/*==========================[output]=============================
Enter a word or sentence: I absolutely love to program!
I have found 10 vowels.
================================================================*/
// end of class VowelCount
Forum:
