Java 在带有准则的arraylist中添加数字

Java 在带有准则的arraylist中添加数字,java,eclipse,Java,Eclipse,我是个新手,需要帮助。我正试图根据我能使用的数字数量,将一个数字的数字相加。我使用EclipseJuno并使用一个单独的文本文件来使用我的数字。虽然不多,但这就是我现在拥有的: public static void main(String[] args) throws IOException{ String token1 = ""; Scanner infile1 = new Scanner(new File("input.txt")); ArrayList<String> tem

我是个新手,需要帮助。我正试图根据我能使用的数字数量,将一个数字的数字相加。我使用EclipseJuno并使用一个单独的文本文件来使用我的数字。虽然不多,但这就是我现在拥有的:

public static void main(String[] args) throws IOException{

String token1 = "";
Scanner infile1 = new Scanner(new File("input.txt"));
ArrayList<String> temps = new ArrayList<String>();
//Adding Input files to the Arraylist
while(infile1.hasNext()){
    token1 = infile1.next();
      temps.add(token1);    
}
infile1.close();
//Calling the Numbers from ArrrayList temps
    for(int x = 0; x < temps.size(); x++) {
 System.out.println(x + " " + temps.get(x));
 for(x = 0; x < temps.size(); x++ ){

 }
}


    } 

}
publicstaticvoidmain(字符串[]args)引发IOException{
字符串标记1=“”;
扫描仪内嵌1=新扫描仪(新文件(“input.txt”);
ArrayList temps=新的ArrayList();
//将输入文件添加到Arraylist
while(infile1.hasNext()){
token1=infile1.next();
临时添加(标记1);
}
infile1.close();
//从ArrrayList temps呼叫号码
对于(int x=0;x
数字是 9678415 7, 9678415 6, 9678415 5, 9678415 4, 2678515 3,
要添加的数字,要使用的数字。input.txt文件没有逗号。具体操作方法取决于文件中数据的外观。你说它不是用逗号分隔的,所以我必须假设它们是用线分隔的。您需要分离字符串中的值并转换为int;因此,如果我理解这个问题,下面的内容应该是你正在尝试的。(完全公开,我用Java编写代码已经有一段时间了,现在还没有办法测试它,请确保我没有犯任何基本语法错误)

ArrayList totalArray=ArrayList();
用于(字符串tStr:temps){
总积分=0;
字符串[]numArray=tStr.split(“”);
for(int x=0;x
可能有更好的方法来获得最高的价值,但由于我已经离开这一点有一段时间了,我将以我能想到的最基本的方式来做

int highestValue = 0;
for (Integer x : totalArray){
    if(highestValue<=x){
        highestValue = x;
    }
}
return highestValue;
int highestValue=0;
对于(整数x:totalArray){

如果(HighestValue我忘了提到返回最高数值您想做的事情的描述不清楚。请给出输入和预期输出的示例。示例输出应该是986541、987641、98765、9876和875。现在我更困惑了。请回答清楚显示输入值的问题,cal的方法计算和预期输出值。P.S.我认为我在这个答案中使用的增强for循环仅在1.5版和更高版本中可用。我们在这一点上已经远远超过了这一点,我想大多数系统都使用了更高版本,但我想您可能需要知道。
int highestValue = 0;
for (Integer x : totalArray){
    if(highestValue<=x){
        highestValue = x;
    }
}
return highestValue;