Charles Bell
Posts: 519
Nickname: charles
Registered: Feb, 2002
|
|
Re: can anyone help to find the error in the code
|
Posted: Mar 10, 2002 6:50 AM
|
|
The lines I revised in you code are commented out with // and replaced with the new line right below it.
import java.io.*; import java.math.*; import java.awt.*; import java.util.*;
public class tempcon { double val; double sq; double fin; String str=""; String temp=""; Integer value; StringTokenizer stToken; int temp1,temp2,temp3,temp4,temp5,x1,x2; int[] array; int[] test; String s1; int[] x; int largestValue; int smallestValue; int largestValueIndex; int smallestValueIndex; Vector dummy=new Vector();
public static void main(String arg[])throws IOException { tempcon t=new tempcon(); t.readinput(); t.vectorToIntArray(); t.FindMax(); //t.FindMin(); }
public void readinput() {
try {
//DataInputStream br=new DataInputStream(new BufferedInputStream(new FileInputStream("file.txt"))); BufferedReader br=new BufferedReader(new FileReader("file.txt"));
while((str=br.readLine())!=null) { stToken= new StringTokenizer(str," ",false); while(stToken.hasMoreTokens()) { temp = stToken.nextToken(); if(temp!=null) { //value = new Integer(temp); dummy.addElement(temp); } } }
} catch(Exception e) { System.out.println("exception"); }
}
public void vectorToIntArray() { Vector v = new Vector(); v = dummy; { array = new int[v.size()]; Enumeration e = v.elements(); for( int i=0; e.hasMoreElements(); i++ ) { try { //array = ((Integer)e.nextElement()).intValue(); array[i] = ((Integer)e.nextElement()).intValue();
} catch(ClassCastException cce) { //array = 0; array[i] = 0; } } } for(int i=0;i<array.length;i++) { //System.out.println(" a :"+array); //double val=(0.3464-(0.0692*(683.72-array))); double val=(0.3464-(0.0692*(683.72-array[i]))); double sq=Math.sqrt(val); double fin=(-0.1732+sq)/(2*0.01732); System.out.println(" the value of fin :"+fin); } }
// to findthe largest value of the temperature array
public void FindMax() { largestValue = array[0];
for(int i = 1; i<array.length; i++) { //if (largestValue < array) { if (largestValue < array[i]) { //largestValue = array; largestValue = array[i]; largestValueIndex = i; } }
}
//to find the smallest value of temaperature array public void FindMin() { smallestValue = array[0]; for(int i = 1; i<array.length; i++) { //if (smallestValue > array) if (smallestValue > array[i]) { //smallestValue = array; smallestValue = array[i]; smallestValueIndex =i; } } }
}
|
|