Java数组存储值 [英] Java Array Storing Values
问题描述
我试图存储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; iSystem.out.print(Criteria:);
crits [i] = inpt.readLine();
for(int j = 0; jSystem.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
crits [i] = inpt.readLine();
System.out.print(Enter Percentage:);
arrayCrit [i] = Integer.parseInt(inpt.readLine());
}
//打印值
for(int i = 0; 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屋!