If, symbols Learn programming Java

Lesson:

Basic Data Types


Exercise:

If, symbols


Objetive:

Create a program to ask the user for a symbol and answer if is an uppercase vowel, a lowercase vowel, 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("insert anything: ");
		symbol = (char)new Scanner(System.in).nextLine();

		if (symbol >= '0' && symbol <= '9')
		{
			System.out.println("it's a number");
		}

		else if ((symbol == 'a') || (symbol == 'e') || (symbol == 'i') || (symbol == 'o') || (symbol == 'u'))
		{
			System.out.println("it's a lowercase vowel");
		}

		else if ((symbol == 'A') || (symbol == 'E') || (symbol == 'I') || (symbol == 'O') || (symbol == 'U'))
		{
			System.out.println("it's a upercase vowel");
		}

		else
		{
			System.out.println("it's a symbol");
		}
	}
}

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