puppyhuang
asked on
Can anyone debug my program?
I know I should do it by myself, but I just can't find more samples to help me. So, please help me debug my program. Thank you.
CC
-------------------------- ---------- ---
import java.io.*;
class LVDT{
public static void main(String args[]) throws IOException
{
double temperature, dest, strain;
String strD1, strD2, strD3;
BufferedReader br = new BufferedReader(new InputStreamReader(System.i n));
System.out.println("Enter Temperature value: ");
strD1 = br.readLine();
temperature = Double.parseDouble(strD1);
System.out.println("------ ---------- --");
System.out.println("You can input either value of the following variable");
System.out.println("1.Dest ");
System.out.println("2.Stra in");
int s = System.in.read();
//System.out.println(s);
switch (s){
case 49:
System.out.println("Enter Dest value: ");
strD2 = br.readLine();
dest = Double.parseDouble(strD2);
System.out.println("Subtra ct Temperature from Crack value is: ");
System.out.print( dest + ((-0.0005)* temperature) -(0.0066) );
break;
case 50:
System.out.println("Enter Strain value: ");
strD3 = br.readLine();
strain = Double.parseDouble(strD3);
System.out.println("Subtra ct Temperature from Strain value is: ");
System.out.print( strain - ((-3.3866)* temperature) -(8.756) );
break;
}
}
}
CC
--------------------------
import java.io.*;
class LVDT{
public static void main(String args[]) throws IOException
{
double temperature, dest, strain;
String strD1, strD2, strD3;
BufferedReader br = new BufferedReader(new InputStreamReader(System.i
System.out.println("Enter Temperature value: ");
strD1 = br.readLine();
temperature = Double.parseDouble(strD1);
System.out.println("------
System.out.println("You can input either value of the following variable");
System.out.println("1.Dest
System.out.println("2.Stra
int s = System.in.read();
//System.out.println(s);
switch (s){
case 49:
System.out.println("Enter Dest value: ");
strD2 = br.readLine();
dest = Double.parseDouble(strD2);
System.out.println("Subtra
System.out.print( dest + ((-0.0005)* temperature) -(0.0066) );
break;
case 50:
System.out.println("Enter Strain value: ");
strD3 = br.readLine();
strain = Double.parseDouble(strD3);
System.out.println("Subtra
System.out.print( strain - ((-3.3866)* temperature) -(8.756) );
break;
}
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Considering you have already gone through the trouble of wrapping System.in in a BufferedReader, it seems a shame to waste the overhead... readLine() will take care of the \r\n, and block until you get one, which i think was the desired result.
Replace the line
int s = System.in.read();
with
int s = Integer.parseInt(br.readLi ne());
This will work fine.
Socrates-Chennai
India
int s = System.in.read();
with
int s = Integer.parseInt(br.readLi
This will work fine.
Socrates-Chennai
India
ASKER
Thanks everybody help me on this program, thank you all.
CC
CC
Replace the line
int s = System.in.read();
with
int s = Integer.parseInt(br.readLi ne());
This will work fine.
Socrates-Chennai
India
int s = System.in.read();
with
int s = Integer.parseInt(br.readLi
This will work fine.
Socrates-Chennai
India
puppyhuang:
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations! No comment means you don't care.
This old question needs to be finalized -- accept an answer, split points, or get a refund. For information on your options, please click here-> http:/help/closing.jsp#1
EXPERTS:
Post your closing recommendations! No comment means you don't care.
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Accept functionpointer's comment as answer.
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
TimYates
EE Cleanup Volunteer
I will leave a recommendation in the Cleanup topic area that this question is:
Accept functionpointer's comment as answer.
Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
TimYates
EE Cleanup Volunteer
int s = System.in.read();
You read only one character and the \r\n is still in the input buffer, so when you try to read the line againt you have empty line. If you want to keep your stile you should do something like this:
int s = System.in.read();
System.in.read();
// then go on