Friday, 1 January 2010
NetBeans Java converter
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Mihai
*/
public class Main {
private final static double CENTIMETERRATE = 2.54;
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String name = "";
double height = 0;
// TODO code application logic here
BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter your name: ");
try {
name = dataIn.readLine();
} catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println("Enter your height, centimeters: ");
try {
height = Double.valueOf(dataIn.readLine());
} catch (IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
System.out.println("Your name is " + name);
System.out.println("Your height is " + convertValue(height, CENTIMETERRATE) + " inches");
}
private static double convertValue(double number, double rate) {
double convertedNumber = 0;
convertedNumber = number / rate;
return convertedNumber;
}
}
Subscribe to:
Posts (Atom)