Not quite sure about this one
Ive been teaching myself to write java by coming up with random
program ideas and working through them. I wrote this code to convert
certain values for measurements, but I seem to have run into a snag. I
am getting odd values for int choice. When it is read here:
int choice= 0;
try{
choice = dataIn.read();
it seems to start with an initial value of 48, though I declare it
with a value of 0. I suspect the
" dataIn.read() " should be changed, but not sure what is wrong here.
The program also ends before reaching the for loop, and I dont know
about that either. Thanks in advance for any help you all may be able
to offer.
Here is the code:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Ian
*/
public class OutputVariable{
public static void main(String[] args){
BufferedReader dataIn = new BufferedReader(new
InputStreamReader( System.in) );
System.out.println("Press 1 for Temperature conversion");
System.out.println(" 2 for Weight conversion");
System.out.println(" 3 for Liquid conversion");
int choice= 0;
try{
choice = dataIn.read();
}catch( IOException e ){
System.out.println("Error!");
}
System.out.println(choice);
for(;choice<=3;){
if(choice==1){
System.out.println("Enter the Temp in fahrenheit:");
double fah=0.0;
double cel= (fah-32)*(5/9);
try{
fah = dataIn.read();
}catch( IOException e ){
System.out.println("Error!");
System.out.println("The Temp in celcius = " + cel);
}
}
if(choice==2){
System.out.println("Enter the Weight in pounds:");
double lbs=0.0;
double kilo= (lbs*2.2);
try{
lbs = dataIn.read();
}catch( IOException e ){
System.out.println("Error!");
System.out.println("The weight in kilograms = " + kilo);
}
if(choice==3){
System.out.println("Enter the volume in gallons:");
double gallon=0.0;
double liters= (3.8*gallon);
try{
gallon = dataIn.read();
}catch( IOException e ){
System.out.println("Error!");
System.out.println("The volume in liters= " + liters);
}
}
}
}
}
}