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

CSE 1007 – Java Programming

Name – Naman Sood


Registration Number – 18BCI0168
Slot - L53+L54
Faculty – Prof. JABANJALIN HILDA J
Questions
1. Find BMI of a person by getting weight and height in kg and cm
respectively from user. [Formula BMI = kg/m2]
2. Write a program to find the simple interest
3. Write a program to display you name, register number and your cgpa
4. Write a program to find the area of circle
5. Check if a given number is odd or even number [using if statement as well
as switch case]
Code
import java.util.Scanner;

public class q1 {
public static void main(String args[]) {
//BMI Calculator
Scanner sc = new Scanner(System.in);
System.out.println("Enter your height in meters: ");
float h = sc.nextFloat();
System.out.println("Enter your weight: ");
float w = sc.nextFloat();
float bmi = w / (h * h);
System.out.println("Your BMI is " + bmi);

System.out.println("----------------------------------
------------------------");

//Simple interest calculator


System.out.println("Enter principle amount");
float p = sc.nextFloat();
System.out.println("Enter rate per annum");
float r = sc.nextFloat();
System.out.println("Enter time period");
float t = sc.nextFloat();
float si = p * r * t / (100);
System.out.println("Simple interest is " + si);
sc.nextLine();
System.out.println("----------------------------------
------------------------");

//Display name, cgpa


System.out.println("Enter your name");
String n = sc.nextLine();
System.out.println("Enter your registration number");
String reg = sc.nextLine();
System.out.println("Enter your CGPA");
float cg = sc.nextFloat();
System.out.println("Your name is: " + n);
System.out.println("Your Registration number is " +
reg);
System.out.println("Your CGPA is " + cg);

System.out.println("----------------------------------
------------------------");
//Area of circle
System.out.println("Enter radius of circle");
float rad = sc.nextFloat();
System.out.println("Area of circle is " + (Math.PI *
rad * rad));

System.out.println("----------------------------------
------------------------");
//Odd even using IF statement
System.out.println("Enter an integer for odd/even
check (using IF)");
int inte = sc.nextInt();
if (inte % 2 == 0) {
System.out.println(inte + " is even");
} else {
System.out.println(inte + " is odd");
}

System.out.println("----------------------------------
------------------------");
//Odd even using Switch case
System.out.println("Enter an integer for odd/even
check (using Switch)");
int inte2 = sc.nextInt();
switch (inte2 % 2) {
case 0:
System.out.println(inte2 + " is Even number");
break;
case 1:
System.out.println(inte2 + " is Odd number");
}
}
}
Outputs
Part – 1, 2, 3

Part – 4, 5

You might also like