【发布时间】:2023-03-21 18:29:01
【问题描述】:
您好,我有一个包含一些 2 位整数的文本文件。我想查找这两个数字中是否有任何一个包含特定的单个数字。文本文件中的示例编号为 12。我想测试这些数字的数字中是否有 1 或 3:
package algoritmahomework3;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;
public class AlgoritmaHomework3 {
private static BufferedReader br = null;
private static String[] split;
private static String fileName = "input.txt";
public static void main(String[] args) throws IOException {
try {
// txt String variable is putting the file's content here.
br = new BufferedReader(new FileReader("C:\\Users\\Alparslan\\Desktop\\input.txt"));
String txt = " ";
String msg = " ";
while((msg = br.readLine()) != null){
txt += msg;
}
for(int i=0; i<txt.length(); i++){
split = txt.split(" ");
// split is a static array to put inside the splitted data which is in txt file.
// This succeed. You can test it using below line of code.
//System.out.println(Arrays.toString(split));
}
printGraph(txt);
} catch (FileNotFoundException ex) {
Logger.getLogger(AlgoritmaHomework3.class.getName()).log(Level.SEVERE, null, ex);
}
}
private static void printGraph(java.lang.String txt) {
if(Integer.parseInt(txt)==1){
}
}
}
【问题讨论】:
-
你的问题到底是什么?
-
我在文本文件中有数字。例如 12。这有 2 个数字。 1 和 2。我想知道 1 是否是那个数字之一
-
str.indexOf('1')!=-1