0% found this document useful (0 votes)
31 views3 pages

CSE 1007 - Java Programming

The document contains code to solve 5 Java programming questions: 1) Calculate BMI from user-input weight and height 2) Calculate simple interest given principal, rate, and time 3) Display a user's name, registration number, and CGPA from user-input 4) Calculate the area of a circle from a user-input radius 5) Check if a user-input number is odd or even using if/else and switch statements

Uploaded by

Naman Sood
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)
31 views3 pages

CSE 1007 - Java Programming

The document contains code to solve 5 Java programming questions: 1) Calculate BMI from user-input weight and height 2) Calculate simple interest given principal, rate, and time 3) Display a user's name, registration number, and CGPA from user-input 4) Calculate the area of a circle from a user-input radius 5) Check if a user-input number is odd or even using if/else and switch statements

Uploaded by

Naman Sood
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/ 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