Professional Documents
Culture Documents
SAVEJ
ROLL NO:- 2102900130028
ABES INSTITUTE OF TECHNOLOGY
BRANCH IT
import java.util.Scanner;
public class evenodd {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int num = input.nextInt();
if ((num % 2) == 0) {
System.out.println("num is even");
} else {
System.out.println("num is odd");
}
}
}
2. WAP to find largest number among three numbers
import java.util.*;
public class pgm2
{
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
int a,b,c;
System.out.print("Enter the number a:");
a=sc.nextInt();
System.out.print("Enter the number b:");
b=sc.nextInt();
System.out.print("Enter the number c:");
c=sc.nextInt();
if((a>b)&&(a>c))
{
System.out.println(a+"Is Greatest");
}
else if ((b>c))
{
System.out.println(b+"Is Greatest");
}
else {
System.out.println(c+"Is Greatest");
}
sc.close();
}
}
3 WAP to check a triangle is a equilateral, isosceles or scalene
import java.util.Scanner;
public class triangle {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("enter the sids of the triangle");
double a = input.nextDouble();
double b = input.nextDouble();
double c = input.nextDouble();
if (a==b && b==c){
System.out.println("triangle is equilateral");
} else if (a==b || b==c || a==c) {
System.out.println("triangle is isosceles");
}else {
System.out.println("triangle is scalen");
}
}
}
4 Write a Java program that reads a floating-point number and prints "zero" if the number
is zero. Otherwise, print "positive" or "negative".
import java.util.Scanner;
}else {
System.out.println("number is" + number);
}
}
}
5 Write a Java program that reads in two floating-point numbers and tests whether they
are the same up to three decimal places.
import java.util.*;
public class program5
{
public static void main(String args[])
{
Scanner sc =new Scanner(System.in);
float a,b;
a=sc.nextFloat();
b=sc.nextFloat();
a= (int)(a*1000);
b=(int)(b*1000);
if(a==b)
{
System.out.println("Both are Equal upto 3 decimal");
}
System.out.println("Both are not Equal");
sc.close();
}
6 Write a Java program that accepts three numbers and prints "All numbers are equal" if
all three numbers are equal, "All numbers are different" if all three numbers are different
and "Neither all are equal or different" otherwise.
Import java.util.Scanner;
public class equal {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int a = input.nextInt();
int b = input.nextInt();
int c = input.nextInt();
if(a==b && b==c && a==c ){
System.out.println("all the numbers are equal");
} else if (a!=b && b!=c && a!=c) {
System.out.println("all numbers are different");
} else {
System.out.println("neither all are equal or different");
}
}
}
7. Write a program that accepts three numbers from the user and prints "increasing" if the
numbers are in increasing order, "decreasing" if the numbers are in decreasing order, and
"Neither increasing or decreasing order" otherwise
import java.util.Scanner;
}
8 WAP to print day name of a week day number starting sunday as day 1.
import java.util.*;
public class program8
{
public static void main(String args[])
{
Scanner sc= new Scanner(System.in);
System.out.println("Enter 1 for Sunday:");
System.out.println("Enter 2 for Monday:");
System.out.println("Enter 3 for Tuesday:");
System.out.println("Enter 3 for Wednesday:");
System.out.println("Enter 3 for Thursday:");
System.out.println("Enter 3 for Friday:");
System.out.print("Enter 4 for Saturday:");
int s=sc.nextInt();
switch(s)
{
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.println("Invalied select");
break;
}
sc.close();
}
}
9. WAP to create a basic calculator using switch.
import java.util.*;
public class program9
{
public static void main(String args[])
{
Scanner sc= new Scanner(System.in);
int a,b;
System.out.print("Enter the value of a:");
a=sc.nextInt();
System.out.print("Enter the value of b:");
b=sc.nextInt();
System.out.println("Enter 1 for addition:");
System.out.println("Enter 2 for Subtraction:");
System.out.println("Enter 3 for multiplication:");
System.out.print("Enter 4 for Division:");
int s=sc.nextInt();
switch(s)
{
case 1:
int c=a+b;
System.out.println("The Sum of"+" "+a+" "+"and"+" "+b+"="+"
"+c);
break;
case 2:
int d=a-b;
System.out.println("The Sub of"+" "+a+" "+"and"+" "+b+"="+"
"+d);
break;
case 3:
int e=a*b;
System.out.println("The Multiplication of"+" "+a+" "+"and"+"
"+b+"="+" "+e);
break;
case 4:
int f=a/b;
System.out.println("The Division of"+" "+a+" "+"and"+"
"+b+"="+" "+f);
break;
default:
System.out.println("Invalied select");
break;
}
sc.close();
}
}