OOP Lab 01 Basic Java, and condtional statements
OOP Lab 01 Basic Java, and condtional statements
3. Write a Java program that asks the user to enter the length and breadth of a rectangle, and then
displays the area of the rectangle on the screen. Save the file as Lab01_3 & class name Lab01_3
import java.util.Scanner;
int l,b,a;
l=sc.nextInt();
b=sc.nextInt();
a=l*b;
System.out.println("Area is "+a);
sc.close();
}}
5. (Convert Celsius to Fahrenheit) Write a program that reads a Celsius degree in a double value
from the console, then converts it to Fahrenheit and displays the result on the screen.
import java.util.Scanner;
public class Lab01_5 {
public static void main ( String[] Strings) {
Scanner input = new Scanner(System.in);
System.out.print ("Enter a degree in Celsius: ");
double celsius = input.nextDouble ();
double fahrenheit = (9.0 / 5.0) * celsius + 32.0;
}
}
6. Write a program that reads an integer between 0 and 1000 and adds all the digits in the integer.
For example, if an integer is 932, the sum of all its digits is 14.
7.Write a complete Java program that declares three variables named as age1, age2, and age3.
Assign any age you wish to each the three variables, then use the println() method to output the
ages to the screen in one row separated by commas.
8. You can use Cramer’s rule to solve the following 2 * 2 system of linear equation. Write a Java
program that solves the following equation and displays the value for x and y in one line on
the screen separated by comma:
9. Write a Java program that asks the user to enter the length, breadth and height of a cuboid from
the keyboard and computes the total area and volume of the cuboid and prints the result on the
screen in one row separated by comma.
10. Write a Java program that find the roots of quadratic equation.
12. Write a Java program that prompts the user to enter any integer from the keyboard, and
checks whether that number is even or odd. Display a message, “number is even” if the
number is even, and “number is odd” if the number entered by the user is odd.
13. Write a Java program that asks the user to enter any number from the keyboard and calculates
how many a digit the number contains: for example,