Programmer Coding

Control Flow Statements

The control flow statements in Java allow you to run or skip blocks of code when
specific conditions are met.
The “if” Statement
The “if” statement in Java works faithfully like in most programming languages. With the help
of “if” you can choose to apply a specific block of code when a precircle condition is met. The
structure of the “if” statement in Java looks like this.
if (condition) {
// code
}

example

package conditional_statement;
import java.util.Scanner;
public class gread {
    public static void main(String[] args) {
        Scanner Sc=new Scanner(System.in);
        System.out.println("enter your mark");
        int a= Sc.nextInt();
        if(a>100) {
            System.out.println(a + "invalid no");
        }
        else {
            if (a >= 65 && a <= 100) {
                System.out.println(a + "gread A");
            } else if (a >= 50 && a < 65) {
                System.out.println(a + "gread B");
            } else if (a >= 35 && a < 50) {
                System.out.println(a + "gread C");
            } else if (a >= 25 && a < 35) {
                System.out.println(a + "gread D");
            } else {
                System.out.println(a + "fail");
            }
        }
    }
}

output
enter your mark
55
55 gread B

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top