Java数组存储值 [英] Java Array Storing Values

查看:185
本文介绍了Java数组存储值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图存储for循环结构中输入的值,以后我将需要使用,但只能在for循环结构中识别。我需要存储的值被识别为程序的其余部分,但不知何故,我得到一个错误找不到符号

 public class TryArray {
public static void main(String args [])throws IOException {
BufferedReader inpt = new BufferedReader(new InputStreamReader(System。

int [] arrayCrit = new int [5];
String [] crits = new String [5];

for(int i = 0; i System.out.print(Criteria:);
crits [i] = inpt.readLine();
for(int j = 0; j System.out.print(Percentage:);
arrayCrit [j] = Integer.parseInt(inpt.readLine());



System.out.println(crits [i] + arrayCrit [j])
}
}
code>

编辑:是的,我可以在for循环中移动打印输出,但是我需要在显示之前先输入所有的值所有的。请帮助我。

解决方案


System.in)); $ p> public static void main(String args [])throws IOException {
BufferedReader inpt = new BufferedReader(new InputStreamReader(
System.in));

int [] arrayCrit = new int [5];
String [] crits = new String [5];

(int i = 0; i System.out.print(Enter Criteria:);
crits [i] = inpt.readLine();
System.out.print(Enter Percentage:);
arrayCrit [i] = Integer.parseInt(inpt.readLine());
}
//打印值
for(int i = 0; i System.out.println(Criteria:+暴击[i] +百分比:
+ arrayCrit [i]);
}
}


I'm trying to store the values inputted on the for-loop structure that I will need for later use, but it can only be recognized inside the for loop structure. I need the stored values to be recognize for the rest of the program but somehow I'm getting an error "cannot find symbol"

public class TryArray {
  public static void main(String args[]) throws IOException {
    BufferedReader inpt = new BufferedReader(new InputStreamReader(System. in ));

    int[] arrayCrit = new int[5];
    String[] crits = new String[5];

    for (int i = 0; i < crits.length; i++) {
      System.out.print("Criteria: ");
      crits[i] = inpt.readLine();
      for (int j = 0; j < arrayCrit.length; j++) {
        System.out.print("Percentage: ");
        arrayCrit[j] = Integer.parseInt(inpt.readLine());
      }
    }

    System.out.println(crits[i] + arrayCrit[j])
  }
}

Edit: Yes, I can move the print output inside the for-loop, but I need to input all the values first before showing all of it. Please I need help.

解决方案

Hope this will help.

public static void main(String args[]) throws IOException {
    BufferedReader inpt = new BufferedReader(new InputStreamReader(
            System.in));

    int[] arrayCrit = new int[5];
    String[] crits = new String[5];

    for (int i = 0; i < crits.length; i++) {
        System.out.print("Enter Criteria: ");
        crits[i] = inpt.readLine();
        System.out.print("Enter Percentage: ");
        arrayCrit[i] = Integer.parseInt(inpt.readLine());
    }
    // Printing the values
    for (int i = 0; i < crits.length; i++) {
        System.out.println("Criteria :" + crits[i] + " Percentage: "
                + arrayCrit[i]);
    }
}

这篇关于Java数组存储值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆