Vowel - switch Learn programming Java

Lesson:

Basic Data Types


Exercise:

Vowel - switch


Objetive:

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


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();

		switch (symbol)
		{
			case 'a':
			case 'e':
			case 'i':
			case 'o':
			case 'u':
				System.out.println("It's a lowercase vowel.");
				break;
			case '0':
			case '1':
			case '2':
			case '3':
			case '4':
			case '5':
			case '6':
			case '7':
			case '8':
			case '9':
				System.out.println("It's a digit.");
				break;
			default:
				System.out.print("It's another symbol.");
				break;
		}
	}
}

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