Java

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

5.

LEAP YEAR

import java.util.Scanner;
public class LeapYear {
public static void main(String[] args){
int year;
System.out.println("Enter a Year : ");
Scanner sc = new Scanner(System.in);
year = sc.nextInt();
if (((year % 4 == 0) && (year % 100!= 0)) || (year%400 == 0))
System.out.println("Encoded year is a leap year");
else
System.out.println("Encoded year is not a leap year");
}
}

6. WORD EQUIVALENT

7. QUADRANT

import java.util.Scanner;
public class Quadrant {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int a,b;
a = sc.nextInt();
b = sc.nextInt();
if(a > 0 && b > 0)
System.out.print("1st Quadrant");
else if(a < 0 && b > 0)
System.out.print("2nd Quadrant");
else if(a < 0 && b < 0)
System.out.print("3rd Quadrant");
else if(a > 0 && b < 0)
System.out.print("4th Quadrant");
else
System.out.print("Origin");
}
}

8. BMI

import java.util.Scanner;
public class BMI {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.print("Input weight in KILOGRAM: ");
double weight = sc.nextDouble();
System.out.print("\nInput height in METERS: ");
double height = sc.nextDouble();
double BMI = weight / (height * height);
System.out.print("\nBody Mass Index(BMI) is: " + BMI + " kg/m2");
}
}

9. HEIGHT COMPARISON

import java.util.Scanner;
public class HeightComparison {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int myHeight,friendHeight;
System.out.println("Enter my Height : ");
myHeight = sc.nextInt();
System.out.print("\nEnter Friend Height : ");
friendHeight = sc.nextInt();

if(myHeight > friendHeight)


System.out.print("I am Taller than my Friend.");
else if(myHeight < friendHeight)
System.out.print("My Friend is Taller than Me.");
else
System.out.print("We are the same Height.");
}
}

10. 3 NUMBERS ASCENDING

import java.util.Scanner;
public class Ascending{
public static void main(String[] args) {

Scanner input = new Scanner(System.in);

System.out.print("Enter three Numbers: ");


int num1 = input.nextInt();
int num2 = input.nextInt();
int num3 = input.nextInt();

if ((num1 < num2) && (num2 < num3)){


System.out.println("The sorted numbers are:"+num1+" "+num2+" "+ num3);
}
if ((num1 < num2) && (num2 > num3)){
System.out.println("The sorted numbers are:"+num1+" "+num3+" "+ num2);
}
if ((num1 > num2) && (num2 > num3)){
System.out.println("The sorted numbers are:"+num3+" "+num2+" "+ num1);
}
if ((num1 > num2) && (num2 < num3)){
System.out.println("The sorted numbers are:"+num2+" "+num1+" "+ num3);
}

}
}

You might also like