1)for循環
for(int i=0; i<crits.length; i++){ //this will execute 5 times
System.out.print("Criteria: ");
crits[i]=inpt.readLine();
for (int j=0; j<arrayCrit.length; j++){ //this will execute 5 times for each i = 25 times
System.out.print("Percentage: ");
arrayCrit[j]=Integer.parseInt(inpt.readLine());
}
}
刪除嵌套for循環添加
import java.io.*;
2)正在使用嵌套作爲
for(int i=0; i<crits.length; i++){ //this will execute 5 times
System.out.print("Criteria: ");
crits[i]=inpt.readLine();
}
for (int j=0; j<arrayCrit.length; j++){ //this will execute 5 times
System.out.print("Percentage: ");
arrayCrit[j]=Integer.parseInt(inpt.readLine());
}
3)can not find symbol
你想在同一時間打印的標準和比例,因爲你已經初始化大小5兩個數組,然後就可以直接打印
for (int i = 0; i < 5; i++) {
System.out.println(crits[i] + arrayCrit[i]);
}
4)可以使用下面的程序,它增強你的程序的版本
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class TestArray {
public static void main(String args[]) throws IOException {
BufferedReader
inpt = new BufferedReader(new InputStreamReader(System. in));
System.out.println("How many records?");//ask for how many records
int n = Integer.parseInt(inpt.readLine());// store in n
int[] arrayCrit = new int[n];//create array with size n
String[] crits = new String[n];
//**as you mentioned in edit you want to take all the input before printing**
for (int i = 0; i < n; i++)
{
System.out.print("Criteria: ");
crits[i] = inpt.readLine();
System.out.print("Percentage: ");
arrayCrit[i] = Integer.parseInt(inpt.readLine());
}
//print both arrays
System.out.println("Criteria \t Percentage");
for (int i = 0; i < n; i++)
{
System.out.println(crits[i] + "\t"+arrayCrit[i]);
}
}
}
有用的鏈接
我讚賞所有幫助傢伙,謝謝。 – user2768501
不客氣。 –