Docsity

Assignment For Coding, Cheat Sheet of Computer Architecture and Organization

Toggle sidebar
bg1
Subject Code: 3140705 Subject Name: OOP-I Date:24/01/2022
Enrolment No: 200420107110 Name: Hit Vaghani
SCET/CO/2020-21/Even/BE Div-II/Sem-IV
Practical No:1
Problem Statement -3:
Write a program that reads a number in meters, converts it to feet, and displays the result.
Program:
import java.util.Scanner;
public class pratical13 {
public static void main(String[] args) {
Scanner inputvar = new Scanner(System.in);
System.out.println("Enter value (in meter)");
float meter = inputvar.nextFloat();
float foot = 3.2808f*meter;
System.out.println("foot =" + foot);
}
}
Output:
Problem Statement -4:
Body Mass Index (BMI) is a measure of health on weight. It can be calculated by taking your
weight in kilograms and dividing by the square of your height in meters. Write a program that
prompts the user to enter a weight in pounds and height in inches and displays the BMI.
Note:- 1 pound=.45359237 Kg and 1 inch=.0254 meters.
Program:
import java.util.Scanner;
public class practical1_4 {
public static void main(String[] args) {
pf3
pf4
pf5

Partial preview of the text

Download Assignment For Coding and more Cheat Sheet Computer Architecture and Organization in PDF only on Docsity!

Enrolment No: 200420107110 Name: Hit Vaghani Practical No: 1 Problem Statement - 3 : Write a program that reads a number in meters, converts it to feet, and displays the result. Program: import java.util.Scanner; public class pratical13 { public static void main(String[] args) { Scanner inputvar = new Scanner(System.in); System.out.println("Enter value (in meter)"); float meter = inputvar.nextFloat(); float foot = 3.2808f*meter; System.out.println("foot =" + foot); } } Output: Problem Statement - 4: Body Mass Index (BMI) is a measure of health on weight. It can be calculated by taking your weight in kilograms and dividing by the square of your height in meters. Write a program that prompts the user to enter a weight in pounds and height in inches and displays the BMI. Note:- 1 pound=.45359237 Kg and 1 inch=.0254 meters. Program: import java.util.Scanner; public class practical1_4 { public static void main(String[] args) {

Enrolment No: 200420107110 Name: Hit Vaghani Scanner inputvar = new Scanner(System.in); System.out.println("Enter Mass in pound"); float mass = inputvar.nextFloat(); System.out.println("Enter height in inch"); float height = inputvar.nextFloat(); float massInkg = (mass * .45359237f); float heightInMeter = (height * .0254f); System.out.println(heightInMeter); float bmi = massInkg / (heightInMeter * heightInMeter); System.out.println("BMI = " + bmi + "kg/m^2"); } } Output: Problem Statement - 5: Write a program that prompts the user to enter three integers and display the integers in decreasing order. Program: import java.util.Scanner; public class practical1_5 { public static void main(String[] args) { Scanner inputvar = new Scanner(System.in);

Enrolment No: 200420107110 Name: Hit Vaghani } } } Output: Problem Statement - 6: Write a program that prompts the user to enter a letter and check whether a letter is a vowel or consonant. Program: import java.util.Scanner; public class practical1_6 { public static void main(String[] args) { Scanner inputvar = new Scanner(System.in); System.out.println("Enter any letter"); char ch = inputvar.next().charAt(0); if (ch == 'a' || ch == 'A' || ch == 'e' || ch == 'E' || ch == 'i' || ch == 'I' || ch == 'o' || ch == 'O' || ch == 'u' || ch == 'U') { System.out.println("Letter "" + ch + "" is vowel "); } else {

Enrolment No: 200420107110 Name: Hit Vaghani System.out.println("Letter "" + ch + "" is consonant "); } } } Output: