我想从criteria.txt文件中读取 ,以标记化并在同一文件的末尾附加标记.该程序抛出异常:No file found!我不知道我的错误在哪里.任何建议都会对我有所帮助.先感谢您!
这是我的代码:
import java.io.*;
import java.util.StringTokenizer;
public class Test
{
private FileReader fr;
private BufferedReader br;
private FileWriter fw;
private BufferedWriter bw;
private StringTokenizer strtok;
private String s;
//constructor
public Test()
{
try
{
fw=new FileWriter("criteria.txt", true);
bw=new BufferedWriter(fw);
try
{
fr=new FileReader("criteria.txt");
br=new BufferedReader(fr);
while((s=br.readLine())!=null)
{
strtok=new StringTokenizer(s," ");
while(strtok.hasMoreTokens())
{
bw.write("\n"+strtok.nextToken());
}
br.close();
}
}
catch(FileNotFoundException e)
{
System.out.println("File was not found!");
}
catch(IOException e)
{
System.out.println("No file found!");
}
bw.close(); …Run Code Online (Sandbox Code Playgroud) 我有一个矢量:
p[0]=0.40816269
p[1]=0.37576407
p[2]=0.16324950
p[3]=0.05282373
Run Code Online (Sandbox Code Playgroud)
我需要以4位小数的形式打印矢量值作为百分比.我试过了:
for(int i=0; i<p.length;i++)
{
System.out.printf("Criterion "+i+" has the weigth=%.4f \n" , p[i]*100);
}
Run Code Online (Sandbox Code Playgroud)
这给了我:
Criterion 0 has the weigth=40.8163, .....
Run Code Online (Sandbox Code Playgroud)
但我想打印:
Criterion 0 has the weigth=40.8163 %, .....
Run Code Online (Sandbox Code Playgroud)
我不能在每行的末尾添加符号"%".如果我尝试:
System.out.printf("Criterion "+i+" has the weigth=%.4f %\n" , p[i]*100);
Run Code Online (Sandbox Code Playgroud)
要么:
System.out.printf("Criterion "+i+" has the weigth=%.4f "+"%\n" , p[i]*100);
Run Code Online (Sandbox Code Playgroud)
程序引发异常.先感谢您!
我试图生成随机基本的数学运算(加法,减法,乘法和除法),有时我的函数返回NaN.我使用了函数parseInt(),但我仍然遇到同样的问题.如果有人可以帮我提出任何建议,我将不胜感激.先感谢您!
Here is my code:
function randNum(min,max)
{
var num = min+Math.floor((Math.random()*(max-min+1)));
return num;
}
var choose, operator, firstNum, secondNum,rightAnswer;
function getProb()
{
var chooseOp=randNum(1,4);
choose=parseInt(chooseOp);
if (choose==1)
{
oprator="+";
var choose1=randNum(0,10);
var choose2=randNum(0,10);
firstNum=parseInt(choose1);
secondNum=parseInt(choose2);
document.getElementById("mathProb").innerHTML=firstNum+operator+secondNum+"=";
rightAnswer=choose1 + choose2;
}
else if (choose==2)
{
operator="-";
var choose1=randNum(0,10);
var choose2=randNum(0,10);
firstNum=parseInt(choose1);
secondNum=parseInt(choose2);
document.getElementById("mathProb").innerHTML=firstNum+operator+secondNum+"=";
rightAnswer=firstNum - secondNum;
}
else if (choose==3)
{
operator="x";
var choose1=randNum(0,10);
var choose2=randNum(0,10);
firstNum=parseInt(choose1);
secondNum=parseInt(choose2);
document.getElementById("mathProb").innerHTML=firstNum+operator+secondNum+"=";
rightAnswer=choose1 * choose2;
}
else if (choose==4)
{
operator="/";
var choose1=randNum(0,10); …Run Code Online (Sandbox Code Playgroud) 我想在表格中间插入一个新行.我正在使用MySql.我怎样才能做到这一点?
我的表中有以下记录:
ZipCode CityName
60101, Addison
60004, Arlington Heights
60502, Aurora
62223, Belleville
61008, Belvidere
60105, Bensenville
60402, Berwyn
60108, Bloomingdal
61701, Bloomington
Run Code Online (Sandbox Code Playgroud)
我想插入一个新记录,但不是在表的末尾.
例如,我想插入:
60103, Bartlett
Run Code Online (Sandbox Code Playgroud)
在第三条记录之后,决赛桌应如下:
60101, Addison
60004, Arlington Heights
60502, Aurora
60103, Bartlett
62223, Belleville
61008, Belvidere
60105, Bensenville
60402, Berwyn
60108, Bloomingdal
61701, Bloomington.
Run Code Online (Sandbox Code Playgroud)
任何建议都会对我有所帮助.先感谢您!