62,616
社区成员
发帖
与我相关
我的任务
分享
import java.util.*;
import java.io.*;
public class test
{
public static void main(String[] args) //throws Exception
{
try{
double tmpCoef;
int tmpExpo;
BufferedReader br = new BufferedReader(new FileReader(new File("data.txt")));
String sLine = "";
int flag = 0;
while ((sLine = br.readLine()) != null)
{
//System.out.println(flag);
String[] ss = sLine.split(" ");
tmpCoef = Double.parseDouble(ss[0]);
tmpExpo = Integer.parseInt(ss[1]);// reads from the file
//System.out.println(tmpCoef+" "+tmpExpo);
//double absTmpCoef = absValue(tmpCoef);
//now stores it to the polynominal
if ( tmpExpo != 0 ||tmpCoef !=0.0 )
{
if (flag == 1)
{
//store the data into a
System.out.println("a: "+flag);
//a.display();
}
else if (flag == 2)
{
//store the data into b
//b.addTerm(tmpCoef, tmpExpo);
System.out.println("b: "+ flag);
}
else if (flag == 3)
{
//store the data into c
//c.addTerm(tmpCoef, tmpExpo);
System.out.println("c: "+ flag);
}
else if (flag ==4)
{
//store the data into d
//d.addTerm(tmpCoef,tmpExpo);
System.out.println("d: "+ flag);
}
else
{
break;
}
}
if (tmpCoef == 0.00 && tmpExpo == 0)
{
flag++;
//continue;
}
}
}
catch(Exception e)
{
System.out.println("exception caught");
}
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package exp1;
/**
*
* @author szhu5
*/
import java.util.*;
import java.io.*;
public class test {
public static void main(String[] args) //throws Exception
{
try {
double tmpCoef;
int tmpExpo;
BufferedReader br = new BufferedReader(new FileReader(new File("d://data.txt")));
String sLine = "";
int flag=0;
while (br.readLine()!=null) {
sLine=br.readLine();
System.out.println(flag);
String[] ss = sLine.split(" ");
tmpCoef = Double.parseDouble(ss[0]);
tmpExpo = Integer.parseInt(ss[1]);// reads from the file
System.out.println(tmpCoef+"---"+tmpExpo);
//System.out.println(tmpExpo);
//double absTmpCoef = absValue(tmpCoef);
//now stores it to the polynominal
//if (tmpExpo != 0 || tmpCoef != 0.0) {
/*if (flag == 1) {
//store the data into a
System.out.println("a: " + flag);
//a.display();
} else if (flag == 2) {
//store the data into b
//b.addTerm(tmpCoef, tmpExpo);
System.out.println("b: " + flag);
} else if (flag == 3) {
//store the data into c
//c.addTerm(tmpCoef, tmpExpo);
System.out.println("c: " + flag);
} else if (flag == 4) {
//store the data into d
//d.addTerm(tmpCoef,tmpExpo);
System.out.println("d: " + flag);
} else {
break;
}*/
//break;
//}
if (tmpCoef == 0.00 && tmpExpo == 0) {
flag++;
//continue;
}
}
} catch (Exception e) {
System.out.println("exception caught");
}
}
}