Write A Java Application To Find The Maximum of Three Integers Entered by The User

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

4. Write a java application to find the maximum of three integers entered by the user.

5. Accept any three names from the keyboard and display “Your Name is” name.
6. Java Program to check Even or Odd number
7. WAP to accept 5 names from user and store them in an array and print them on screen in
order.
8. WAP to print highest and lowest total marks of 10 students using Arrays.
9. Write a program in Java to enable user to handle divide by zero exception
10. Write a program in Java to create class Triangle with the data members base, height,
area and color. The members base, height, area are of type double and color is of type
string. Write getter and setter methods for base, height and color, and write method to
compute_area (). Create two object of class Triangle, compute their area, and compare their
area and color. If area and color both are same for the objects then display "Matching
Triangles" otherwise display "Non matching Triangles".

public class Triangle {


private double base;
private double height;
private double area;
private String color;
double getBase( ) {
return base;
}
double getHeight( ) {
return height;
}
String getColor ( ) {
return color;
}
void setBase(double newbase) {
base = newbase;
}
void setHeight(double newheight) {
base = newheight;
}
void setColor(String newcolor) {
color = newcolor;
}
double ComputeArea ( ) {
area= 0.5*base*height;
return area;
}
public static void main(String[] args) {
Triangle T1 = new Triangle();
Triangle T2 = new Triangle();
T1.setBase(40.0);
T1.setColor("green");
T1.setHeight(20.0);
T2.setBase(50.0);
T2.setColor("blue");
T2.setHeight(10.0);
T1.ComputeArea();
T2.ComputeArea();
if(T1.getColor()==T2.getColor()&&T1.ComputeArea()==T2.ComputeArea())
System.out.println("Matching Triangles");
else
System.out.println("Non Matching Triangles");
}
}
11. Write a program to create three threads in Java and set their priority.
12. Write a Java code to search an element from the array using
binary search technique.
13. Program to swap two numbers
14. Write a java program for calculator which performs addition, subtraction,
multiplication and division

import java.util.Scanner;

public class Calculator{

public static void main(String[] args){


int a,b,c;
int choice;
Scanner scanner = new Scanner(System.in);

while(true) {
System.out.println("Press 1 for Addition");
System.out.println("Press 2 for Subtraction");
System.out.println("Press 3 for Multiplication");
System.out.println("Press 4 for Division");
System.out.println("Press 5 to Quit\n \n ");

System.out.println("Make your choice");


choice = scanner.nextInt();
switch (choice) {

case 1:
System.out.println("Enter the first number ");
a = scanner.nextInt();
System.out.println("Enter the second number");
b = scanner.nextInt();
c = a + b;
System.out.println("The sum of the numbers is = " + c +"\n");
break;

case 2:
System.out.println("Enter the first number ");
a = scanner.nextInt();
System.out.println("Enter the second number");
b = scanner.nextInt();
c = a - b;
System.out.println("The difference of the numbers is = " + c +"\n");
break;

case 3:
System.out.println("Enter the first number");
a = scanner.nextInt();
System.out.println("Enter the second number");
b = scanner.nextInt();
c = a * b;
System.out.println("The product of the numbers is = " + c + "\n");
break;

case 4:
System.out.println("Enter the first number");
a = scanner.nextInt();
System.out.println("Enter the second number");
b = scanner.nextInt();
c = a / b;
System.out.println("The quotient is = " + c +"\n");
break;

case 5:
System.exit(0);

default:
System.out.println("Invalid choice!!! Please make a valid choice. \\n\\n");
}
}
}
}
15. Write a Java program with method to print cube of a number

You might also like