Tech Blog   »   Home   »   Coders Forum   »   Computer Directory   »   Math Calculators   »   RSS:Directory|Forum 

JAVA Source Code   » Coders Community: Forum


JAVA Source Code Examples:

JAVA Source Code: Star Pyramid using JAVA

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








JAVA Source Code: Vowel Count using JAVA

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







JAVA Source Code


Code Examples:
Variables
Strings
Arrays
Functions:
Return Values
Pass by Value
Pass by Reference
Loops:
While loop
Do-while
For loop
Arrays:
Basic




JAVA Compiler: Eclipse

JAVA and C++ Similar:
JAVA VS. C++



Forum Area maSpinner

The forum contains more JAVA programming examples.





Validated with no errors:

Valid XHTML 1.0 Transitional     Valid CSS!


Site Map