0% found this document useful (0 votes)
14 views

Lab

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Lab

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

(1) Check whether a number is even or odd.

Solve:
public class main {
public static void main(String[] args){
int num = 10;
if (num % 2 == 0) {
System.out.println(num + " is even");
}
else {
System.out.println(num + " is odd");

}
}
}

(2) Check whether a number is positive or negative.


Solve:
public class main {
public static void main(String[] args){
int num = -25;
if (num > 0) {
System.out.println(num + " is positive");

}
else if (num < 0) {
System.out.println(num + " is negative");

}
else {
System.out.println(num + " is zero");

}
}
}
(3) Check whether a year is LEAP YEAR or Not.
Solve:
public class main {
public static void main(String[] args){
int year = 2002;
if ((year % 4 == 0) && (year % 100 != 0 || year % 400 == 0)) {
System.out.println(year + " is a leap year");
}
else {
System.out.println(year + " is not a leap year");
}
}
}

(4) Find out the maximum value of three numbers.


Solve:
public class main {
public static void main(String[] args){
int num1 = 10;
int num2 = 20;
int num3 = 30;
int max = num1;
if (num2 > max) {
max = num2;
}
if (num3 > max) {
max = num3;

}
System.out.println("The maximum value is: " + max);
}
}
(5) Make a simple calculator.

Solve:

import java.util.Scanner;

public class cal {


public static void sum(int num1,int num2){
int sum=num1+num2;
System.out.println("Your sum is:"+sum);

public static void sub(int num1,int num2){


int sum=num1-num2;
System.out.println("Your sub is:"+sum);

public static void mul(int num1,int num2){


int sum=num1*num2;
System.out.println("Your multipication is:"+sum);

public static void div(double num1,int num2){


double sum=num1/num2;
System.out.println("Your sum is:"+sum);

public static void rem(int num1,int num2){


int sum;
if(num1>num2)
sum=num1%num2;
else
sum=num2%num1;
System.out.println("Your sum is:"+sum);

public static void main(String[] args) {


Scanner input = new Scanner(System.in);
int choice=0,num1,num2;
while (choice < 6) {
System.out.print("\n");
System.out.print("Enter the 1st number:");
num1=input.nextInt();

System.out.print("Enter the 2nd number:");


num2=input.nextInt();

System.out.println("Enter 1 for Addtion");


System.out.println("Enter 2 for Subtraction");
System.out.println("Enter 3 for Multipication");
System.out.println("Enter 4 for division");
System.out.println("Enter 5 for Remainder");
System.out.println("Enter 6 for Exit");
System.out.print("Enter a number:");
choice = input.nextInt();

switch (choice) {
case 1:
sum(num1,num2);
break;
case 2:
sub(num1,num2);
break;
case 3:
mul(num1,num2);
break;
case 4:
div(num1,num2);
break;
case 5:
rem(num1,num2);
break;
case 6:
choice=6;
break;
}

}
}
}

You might also like