Conditional Statements in Java. Here we can discuss about if, if..else,if..elseif..else, switch and looping statements like for, while and do..while along with programs.
In Java, control structures determine the flow of execution of a program. They enable decision-making, looping, and branching, allowing programs to handle different situations dynamically.
Similar to Conditional Statements in Java. Here we can discuss about if, if..else,if..elseif..else, switch and looping statements like for, while and do..while along with programs.
Conditional Statements in Java. Here we can discuss about if, if..else,if..elseif..else, switch and looping statements like for, while and do..while along with programs.
CHECK EVEN ORODD USING IF-
ELSE
import java.util.Scanner;
public class EvenOddScanner {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter an integer: ");
int number = sc.nextInt();
if (number % 2 == 0)
System.out.println(number + " is Even");
else
System.out.println(number + " is Odd");
}
}
7.
PROGRAM WITH BUFFEREDREADER
–GRADING WITH IF-ELSE IF
import java.io.*;
public class GradeChecker {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter your marks: ");
int marks = Integer.parseInt(br.readLine());
if (marks >= 90)
System.out.println("Grade A");
else if (marks >= 75)
System.out.println("Grade B");
else if (marks >= 60)
System.out.println("Grade C");
else
System.out.println("Fail");
}
}
PRINT MULTIPLICATION TABLE
USINGFOR LOOP
import java.util.Scanner;
public class MultiplicationTable {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter number: ");
int num = sc.nextInt();
for (int i = 1; i <= 10; i++) {
System.out.println(num + " x " + i + " = " + (num * i));
}
}
}
13.
SUM OF NUMBERSUSING WHILE
LOOP
import java.io.*;
public class SumUsingWhile {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
System.out.print("Enter the limit: ");
int n = Integer.parseInt(br.readLine());
int sum = 0, i = 1;
while (i <= n) {
sum += i;
i++;
}
System.out.println("Sum = " + sum);
}
}