尝试用java打印数组

尝试用java打印数组,java,arrays,Java,Arrays,我需要提交一个代码,每次尝试运行它时,都会一次又一次地出现相同的错误 问题是 编写以下Java方法: (a) 。readValues可将十个整数值输入到整数数组中 文本文件“Values.txt”中的选项卡。此数组选项卡将传递给 方法作为参数。假设文件中的学生人数为 等于数组的长度 (b) 。oddValues,它将数组选项卡作为参数并返回 在选项卡中找到的奇数值数 (c) 。将数组选项卡作为参数的replaceOdd。它应该 用所有奇数值之和替换选项卡中的每个奇数值 提示:您的方法必须首先计算

我需要提交一个代码,每次尝试运行它时,都会一次又一次地出现相同的错误

问题是

编写以下Java方法:

(a) 。readValues可将十个整数值输入到整数数组中 文本文件“Values.txt”中的选项卡。此数组选项卡将传递给 方法作为参数。假设文件中的学生人数为 等于数组的长度

(b) 。oddValues,它将数组选项卡作为参数并返回 在选项卡中找到的奇数值数

(c) 。将数组选项卡作为参数的replaceOdd。它应该 用所有奇数值之和替换选项卡中的每个奇数值

提示:您的方法必须首先计算所有奇数值之和

(d) 。以数组选项卡作为参数并打印的PrintValue 它的内容会显示在屏幕上

(e) 。main声明数组选项卡并调用上述四个 方法

注意:在您的程序中,使用前面提到的方法和变量名 上面

这是代码:

import java.util.*;
import java.io.*;

public class Finalexam
{
    public static void main (String [] args ) throws FileNotFoundException 
{
    int sum=0;
    int [] TAB=new int [10];
    ReadValues(TAB);
    oddValues(TAB);
    replaceOdd(TAB);
    printValues(TAB);

    System.out.println("The sum is" + sum);

}
public static void ReadValues (int [] TAB)
{
 {   int i;
    for(i=0; i<10; i++){
     Scanner s = new Scanner ("Values.txt") ;
     TAB[i]=s.nextInt();
    }
}
    s.close();
}
public static double oddValues(int[] TAB)
{
    int i;
    double odd=0;
    int fn=0;
    for(i=1; i<odd; i++){

    
    while(odd % 2 !=0)
        {
            odd = fn;
        }
        break;
    }
    return fn;
}

public static int replaceOdd(int[] TAB)
{
    int re=0;
    for(int i=0; i<TAB.length; i++){
        re = re/TAB.length;
    }
    return re;
}
public static void printValues(int[] TAB)
{
    int i;
    for(i=0; i<10; i++){
        System.out.println(TAB[i]+"\t");
    }
    System.out.println();
}
}
import java.util.*;
导入java.io.*;
公开课终场
{
公共静态void main(字符串[]args)引发FileNotFoundException
{
整数和=0;
int[]TAB=新int[10];
读取值(选项卡);
ODD值(选项卡);
替换奇数(选项卡);
打印值(选项卡);
System.out.println(“总和为”+总和);
}
公共静态void ReadValues(int[]选项卡)
{
{int i;

对于(i=0;i首先,代码中存在编译错误

用你的方法

public static void ReadValues (int [] TAB)
    {
        {   int i;
            for(i=0; i<10; i++){
                Scanner s = new Scanner ("Values.txt") ;
                TAB[i]=s.nextInt();
            }
        }
        s.close();
    }

循环将永远不会以
odd
0
的形式执行,因此如果您可以添加问题中遇到的错误,则iIt将非常有用。似乎存在多个错误。例如,s未定义。此外,在方法readValue中,似乎不需要{}。我认为您应该分离错误并单独询问。在ReadValues方法中,您有编译问题。在for循环外部声明scanner。
public static void readValues (int [] tab){
        int i;
        Scanner s = new Scanner ("Values.txt") ;
        for(i=0; i<10; i++){
                tab[i]=s.nextInt();
        }
        s.close();
}
public static double oddValues(int[] TAB) {
    int i;
    double odd = 0;
    int fn = 0;
    for (i = 1; i < odd; i++) {

        while (odd % 2 != 0) {
            odd = fn;
        }
        break;
    }
    return fn;
}
public static int replaceOdd(int[] TAB){
    int re=0;
    for(int i=0; i<TAB.length; i++){
        re = re/TAB.length;
    }
    return re;
}