Day 3 - 17 August, 2024

Program 10: WAP to find the greatest Number in three unequal Numbers

import java.util.*; class P1 { public static void main(String[] args) { int a, b, c; Scanner sc = new Scanner(System.in); System.out.print("Enter the value of a : "); a = sc.nextInt(); System.out.print("Enter the value of b : "); b = sc.nextInt(); System.out.print("Enter the value of c : "); c = sc.nextInt(); if (a > b && a > c) { System.out.print(a + "(a) is the greatest number"); } if (b > a && b > c) { System.out.print(b + "(b) is the greatest number"); } else { System.out.print(c + "(c) is the greatest number"); } } } Copy Code
Expected Output:
Input:
Enter the value of a : 10
Enter the value of b : 20
Enter the value of c : 30

Output:
30(c) is the greatest number

Program 11: WAP to take day number as input and display day of week

import java.util.*; class P2 { public static void main(String[] args) { int dn; Scanner sc = new Scanner(System.in); System.out.print("Enter the day number : "); dn = sc.nextInt(); switch (dn) { case 1: System.out.print("Sunday"); break; case 2: System.out.print("Monday"); break; case 3: System.out.print("Tuesday"); break; case 4: System.out.print("Wednesday"); break; case 5: System.out.print("Thursday"); break; case 6: System.out.print("Friday"); break; case 7: System.out.print("Saturday"); break; default: System.out.print("Invalid Day"); } } } Copy Code
Expected Output:
Input:
Enter the day number : 3

Output:
Tuesday

Program 12: WAP to print number up to a limit defined by user

import java.util.*; class P3 { public static void main(String[] args) { int n; Scanner sc = new Scanner(System.in); System.out.print("Enter Maximum Limit : "); n = sc.nextInt(); int i = 1; while (i <= n) { System.out.print(i + " "); i++; } } } Copy Code
Expected Output:
Input:
Enter Maximum Limit : 5

Output:
1 2 3 4 5