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

EXP 3 java

The document contains a series of Java programming exercises demonstrating the use of conditional statements, loops, and logical operators. It includes programs for checking eligibility based on age and marks, determining if a number is even or odd, utilizing switch-case with characters, displaying numbers from 1 to 20 using different loops, and implementing logical operators in a do-while loop. Each program is presented with code snippets and explanations of their functionality.

Uploaded by

hshzjbzbs
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

EXP 3 java

The document contains a series of Java programming exercises demonstrating the use of conditional statements, loops, and logical operators. It includes programs for checking eligibility based on age and marks, determining if a number is even or odd, utilizing switch-case with characters, displaying numbers from 1 to 20 using different loops, and implementing logical operators in a do-while loop. Each program is presented with code snippets and explanations of their functionality.

Uploaded by

hshzjbzbs
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Aashay Kulkarni 183 SYCO c

EXP 3

1. Write a program to check multiple conditions using if statement along with logical operators.

public class trail { //exp3 q1


public static void main(String [] args) {
int age = 20;
double marks = 85.5;

if (age >= 18 && marks > 80) {


System.out.println("Eligible for admission.");
} else if (age >= 18 || marks > 50) {
System.out.println("Considered for admission.");
} else {
System.out.println("Not eligible.");
}
}
}

2.Write a program to check no is even or odd.

import java.util.Scanner;

public class trail {


public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a number: ");
int num = sc.nextInt();

if (num % 2 == 0) {
System.out.println(num + " is Even.");
} else {
System.out.println(num + " is Odd.");
}
}
}
Aashay Kulkarni 183 SYCO c

3. Write a program to check switch-case using character datatype.

import java.util.Scanner;

public class trail {


public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter a character (A/B/C): ");
char ch = sc.next().charAt(0);

switch (ch) {
case 'A':
System.out.println("You selected A.");
break;
case 'B':
System.out.println("You selected B.");
break;
case 'C':
System.out.println("You selected C.");
break;
default:
System.out.println("Invalid choice.");
}
}
}
Aashay Kulkarni 183 SYCO c

4. Write a program to display 1 to 20 numbers using for, while and do-while loop.

public class Trail {

public static void main(String[] args) {

System.out.println("Using for loop:");

for (int i = 1; i <= 20; i++) {

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

System.out.println("\nUsing while loop:");

int j = 1;

while (j <= 20) {

System.out.print(j + " ");

j++;

System.out.println("\nUsing do-while loop:");

int k = 1;

do {

System.out.print(k + " ");

k++;

} while (k <= 20);

}
Aashay Kulkarni 183 SYCO c

5. Develop a program to use logical operators in do-while loop.

import java.util.Scanner;

public class Trail {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

int number;

do {

System.out.print("Enter a positive number (or -1 to exit): ");

number = sc.nextInt();

if (number > 0 && number % 2 == 0) {

System.out.println("Even number entered.");

} else if (number > 0 && number % 2 != 0) {

System.out.println("Odd number entered.");

} while (number != -1);

System.out.println("Exited the loop.");

You might also like