-2
これは私のコードです.b [i]はファイル名test.txtに書き込むが動作しません。それは記号のようなものを書くだけです。助けてくれてありがとう。FileWriterで数値を書くことができません
public class btl {
public static boolean IsPrime(int n) {
if (n < 2) {
return false;
}
int squareRoot = (int) Math.sqrt(n);
for (int i = 2; i <= squareRoot; i++) {
if (n % i == 0) {
return false;
}
}
return true;
}
public static void main(String args[]) {
Scanner scanIn = new Scanner(System.in);
int first = 0;
int second = 0;
try {
System.out.println("Input First Number");
first = scanIn.nextInt();
System.out.println("Input Second Number");
second= scanIn.nextInt();
}
catch(Exception e) {
System.out.println("Something wrong!");
}
int x = first;
int y = second;
int a;
int[] b = new int[y];
Thread threadA = new Thread(new Runnable() {
@Override
public void run() {
int c=0;
for(int i=x; i<y; i++) {
if(IsPrime(i)) {
b[c] = i;
System.out.println(b[c]);
c++;
}
}
}
});
threadA.start();
try(FileWriter fw = new FileWriter("test.txt")){
for(int i =0; i<y; i++)
{
fw.write(b[i]);
}
}
catch(IOException exc) {
System.out.println("EROR! " + exc);
}
}
}
てFileWriterはファイルTEXT.TXTで記号を書き、なぜ私は知りません。配列b [i]の番号が必要です。
。彼らは文字列ではなく、16進数です。テキストが必要な場合は、文字列に変換してから出力します。 –