Vowel - if Learn programming Java

Lesson:

Basic Data Types


Exercise:

Vowel - if


Objetive:

Create a java program to ask the user for a symbol and respond if it's a vowel (in lowercase), a digit, or any other symbol, using "if".


Code:

import java.util.*;
public class Main
{
	public static void main(String[] args)
	{
		char symbol;

		System.out.print("Enter a symbol: ");
		symbol = (char)new Scanner(System.in).nextLine();

		if ((symbol == 'a') || (symbol == 'e') || (symbol == 'i') || (symbol == 'o') || (symbol == 'u'))
		{
			System.out.println("It's a lowercase vowel.");
		}
		else if ((symbol >= '0') && (symbol <= '9'))
		{
			System.out.println("It's a digit.");
		}
		else
		{
			System.out.print("It's another symbol.");
		}
	}
}

Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.