Day 2 - 16 August, 2024

Program 5: WAP to take user name as input and print a message with his name

import java.util.Scanner; class P1 { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter your name: "); String naam = scanner.nextLine(); System.out.println("Hello, " + naam + "!"); } } Copy Code
Expected Output:
Input:
Enter your name: John

Output:
Hello, John!

Program 6: WAP to convert temperature from Centigrade to Fahrenheit

import java.util.*; class P2 { public static void main(String[] args) { double c, f; Scanner sc = new Scanner(System.in); System.out.print("Enter Temperature in Centigrade : "); c = sc.nextDouble(); f = (9 * c) / 5 + 32; System.out.print("Temperature in Fahrenheit : " + f); } } Copy Code
Expected Output:
Input:
Enter Temperature in Centigrade: 25

Output:
Temperature in Fahrenheit: 77.0

Program 7: WAP to convert temperature from Fahrenheit to Centigrade

import java.util.*; class P3 { public static void main(String[] args) { double c, f; Scanner sc = new Scanner(System.in); System.out.print("Enter Temperature in Fahrenheit : "); f = sc.nextDouble(); c = (f - 32) * 5 / 9; System.out.print("Temperature in Centigrade : " + c); } } Copy Code
Expected Output:
Input:
Enter Temperature in Fahrenheit: 77

Output:
Temperature in Centigrade: 25.0

Program 8: Use of if statement

import java.util.*; class P4 { public static void main(String[] args) { int n; Scanner sc = new Scanner(System.in); System.out.print("Enter a number : "); n = sc.nextInt(); if (n == 1) { System.out.print("Hiii Hardik!!"); } System.out.println("Bye Hardik!!"); } } Copy Code
Expected Output:
Input:
Enter a number: 1

Output:
Hiii Hardik!!
Bye Hardik!!

Program 9: WAP to find the greatest number in two unequal numbers

import java.util.*; class P5 { public static void main(String[] args) { int a, b; 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(); if (a > b) { System.out.println("a is greater than b."); } else { System.out.println("b is greater than a."); } } } Copy Code
Expected Output:
Input:
Enter the value of a: 10
Enter the value of b: 20

Output:
b is greater than a.