0% found this document useful (0 votes)
8 views

Control Statements

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Control Statements

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

Control Statement:

Types Of Control Statement:

1)DecisionMaking Statement/(Selection Statement)/Conditional Statements:

1)if Statement
2)if else Statement
3)if else ladder
4)nested if
5)switch statement

2)Iterative Statement.(Looping Statement)

1)for loop
2)while loop
3)do while loop
4)forEach loop

1)DecisionMaking Statement.(Selection Statement)

1)if Statement: It is used when we want test condition.

syntax: if(condition){
---------------
}

Example :

package decisionMakingStatements;

public class IfDemo {

public static void main(String[] args) {

int a=14;

if(a > 10) {


System.out.println("14 is greater than 10");
}
}
}

Example :

package decisionMakingStatements;

import java.util.Scanner;

public class IfDemo {


public static void main(String[] args) {

Scanner sc = new Scanner(System.in);


System.out.println("Enter no");
int no = sc.nextInt();
if (no > 10) {
System.out.println("no is greater than 10");
}
}
}

2)if else Statement :

Syntax : if(condition){
------------
}else{
--------------
}

Example :

package decisionMakingStatements;

import java.util.Scanner;

public class IfElseDemo {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);


System.out.println("Enter you age");
int age = sc.nextInt();
if (age >= 18) {
System.out.println("You are eliigible for voting");
} else {
System.out.println("You are not eligible for voting");
}
}
}

3)if else ladder:

if(){
---------
}else if(){
------------
}else if(){
------------
} else{

Example :

package decisionMakingStatements;

import java.util.Scanner;

public class IfElseLadder {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);


System.out.println("Enter your Marks");
int marks = sc.nextInt();
if (marks > 100) {
System.out.println("Invalid input");
} else if (marks > 80) {
System.out.println("You are in first class");
} else if (marks >= 60 && marks <= 80) {
System.out.println("You are in Second class");

} else if (marks >= 40 && marks < 60) {


System.out.println("You are in Third class");
} else {
System.out.println("You are not eligible for taking admission in
Next clas");
}

}
}

You might also like