0% found this document useful (0 votes)
3 views3 pages

OOP Lab 01 Basic Java, and condtional statements

The document outlines a series of Java programming exercises for students in the Object Oriented Programming course at Raya University. It includes instructions for creating Java applications, performing calculations, and implementing various programming concepts such as user input, loops, and conditionals. Each exercise is designed to enhance the students' understanding of Java programming through practical implementation.

Uploaded by

Stricker Man
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
3 views3 pages

OOP Lab 01 Basic Java, and condtional statements

The document outlines a series of Java programming exercises for students in the Object Oriented Programming course at Raya University. It includes instructions for creating Java applications, performing calculations, and implementing various programming concepts such as user input, loops, and conditionals. Each exercise is designed to enhance the students' understanding of Java programming through practical implementation.

Uploaded by

Stricker Man
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 3

Raya University

Collage of Engineering and Technology


Department of Computer Science
Object Oriented Programming in Java-Lab 01
1. Open NetBeans IDE, and click File -> New Project -> java -> java Application -> give any
project name -> finish, then right click on the project name, select new then java application.
Name the class as Lab01_1, then Type the following Java program shown below as it is and
run the program. put your name where it says name and your department where it says
department.

public class Lab01_1 {


public static void main ( String[] args){
System.out.println("Name: Gebriye Embafresu");
System.out.println("Department: Computer Science");
System.out.println("Course Title: Object Oriented Programming");
}}
2. Write a Java program that asks you to enter your full name and display it on the screen.

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;

public class Lab01_3 {

public static void main(String[] args) {

Scanner sc=new Scanner(System.in);

int l,b,a;

System.out.println("Enter l and b from keyboard ");

l=sc.nextInt();

b=sc.nextInt();

a=l*b;

System.out.println("Area is "+a);

sc.close();

}}

©2021, Instructor: Gebriye Embafresu Website: sites.google.com/site/techroomforcs ~1~


4. Write a Java program that asks the user to enter any two integers from the keyboard and
displays sum, product, and average of the numbers. declare the numbers as num1, and num2
respectively.

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.

The equation for conversion is Fahrenheit= (9/5) *Celsius +32;

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;

System.out.println(celsius + " degree Celsius is equal to " + fahrenheit + " in Fahrenheit");

}
}

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:

3.4x + 50.2y = 44.5

2.1x + .55y = 5.9

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.

©2021, Instructor: Gebriye Embafresu Website: sites.google.com/site/techroomforcs ~2~


11. Write a Java program that asks the user to enter a guess for your age. If the user types in the
correct answer, display a message saying that they were correct, if not, show a message
saying that their guess was wrong. Use your actual age in this program.

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,

Enter a number: 3756


The number 3756 has 4 digits
You may assume that the number has no more than 6 digits. Hint: use else if ladder statements
to test the number.

©2021, Instructor: Gebriye Embafresu Website: sites.google.com/site/techroomforcs ~3~

You might also like