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

ControlStatement

Uploaded by

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

ControlStatement

Uploaded by

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

ControlStatement

public class ControlStatementExample {

public static void main(String[] args) {

int number = 5;

// If-Else Control Statement

if (number % 2 == 0) {

System.out.println(number + " is an even number.");

} else {

System.out.println(number + " is an odd number.");

// For Loop to print first ten even numbers

System.out.println("The first ten even numbers are:");

for (int i = 0; i < 10; i++) {

System.out.print(i * 2 + " ");

Switch statement programme

import java.util.Scanner;

public class MonthSwitchExample {

public static void main(String[] args) {

Scanner scanner = new Scanner(System.in);


System.out.print("Enter a month number (1-12): ");

int month = scanner.nextInt();

// Switch control statement

String monthName;

switch (month) {

case 1:

monthName = "January";

break;

case 2:

monthName = "February";

break;

case 3:

monthName = "March";

break;

case 4:

monthName = "April";

break;

case 5:

monthName = "May";

break;

case 6:

monthName = "June";

break;

case 7:

monthName = "July";

break;
case 8:

monthName = "August";

break;

case 9:

monthName = "September";

break;

case 10:

monthName = "October";

break;

case 11:

monthName = "November";

break;

case 12:

monthName = "December";

break;

default:

monthName = "Invalid month number. Please enter a number between 1 and 12.";

System.out.println(monthName);

scanner.close();

You might also like