-10102 Ex3 Answer- Chan Ka Ho(50661340)
| Part 1 answer | >HOME< | Lab3ans |
| Lab4ans | Lab5ans |
/* Program Name1.java **
** 50661340 Chan Ka Ho **
** This program prints name and student number in one line */
import java.io.*;
public class Name1 {
public static void main(String[] arg) {
System.out.println("Chan Ka Ho 50661340") ;
}
}
/* Program Name2.java **
** 50661340 Chan Ka Ho **
** This program prints name and student number in two line */
import java.io.*;
public class Name2 {
public static void main(String[] arg) {
System.out.println("Chan Ka Ho\n50661340") ;
}
}
/* Program Metric.java **
** 50661340 Chan Ka Ho **
** This program converts pounds and Ounces to kilograms */
import java.io.*;
public class Metric {
public static void main(String[] arg) throws IOException {
float w;
int p ;
int oz ;
final int OZS_PER_LB = 16;
final int GRAM_PER_OZ = 28;
final float KG_PER_GRAM = 0.001f;
System.out.println("English - metric conversion program.\nEnter the weight in pounds and ounces.") ;
System.out.print("Pounds: ");
p = Integer.parseInt((new BufferedReader(new InputStreamReader(System.in))).readLine());
System.out.print("Ounces: ");
oz = Integer.parseInt((new BufferedReader(new InputStreamReader(System.in))).readLine());
System.out.println();
w = (KG_PER_GRAM * (p * OZS_PER_LB + oz )) * GRAM_PER_OZ ;
System.out.println("That's " + w / KG_PER_GRAM+ " grams, or "+ w +" kilograms.");
}
}