Control Statements In Java Example

Chapter: Control Statements Last Updated: 19-06-2016 19:28:47 UTC

Program:

            /* ............... START ............... */
                
import java.util.Scanner;

public class JavaControlStatementsExample {

	public static void main(String[] args) {
		int age;
		Scanner scanner = new Scanner(System.in);
		System.out.print("Please enter Age: ");
		age = scanner.nextInt();
		if (age >= 18)
			System.out.println("above 18 ");
		else
			System.out.println("below 18");

		System.out.print("Please enter Age: ");
		age = scanner.nextInt();
		if (age >= 18 && age <= 35)
			System.out.println("between 18-35 ");
		else if (age > 35 && age <= 60)
			System.out.println("between 36-60");
		else
			System.out.println("not matched");
	}
}

                /* ............... END ............... */
        

Output

Please enter Age: 40
above 18 
Please enter Age: 
50
between 36-60

Notes:

  • Java Control statements control the order of execution in a java program, based on data values and conditional logic.

Tags

Control Statements, Java

Similar Programs Chapter Last Updated
Java For Loop And ForEach Loop Example Control Statements 03-09-2016
Java Enum And Switch Statement Control Statements 03-09-2016
If Statement In Java Example Control Statements 17-06-2016
Java Switch Example Control Statements 14-06-2016
While Loop In Java Example Control Statements 08-06-2017
Return Statement In Java example Control Statements 15-07-2016
Print Stars In Java Example Control Statements 15-07-2016
Nested Loop In Java Example Control Statements 15-07-2016
Infinite While Loop In Java Control Statements 10-06-2016
Infinite Loop In Java Example Control Statements 15-07-2016
If Else Statement In Java Example Control Statements 10-06-2016
For Loop In Java Example Control Statements 07-06-2017
For Each In Java Example Control Statements 07-06-2017
Do While Loop In Java Example Control Statements 10-06-2016
Continue Statement In Java Example Control Statements 30-03-2017
Java Break Statement Example Control Statements 06-07-2016

1