나는 주자를위한 간단한 통계 프로그램을 개발 중입니다. 한 레이스에 대해서만 데이터를 사용합니다. 내가 stackoverflow에서 도움을 후 첫 번째 부분에 대한 실행 코드가! 경기가 끝나면 주자의 이름과 시간을 입력 할 수 있습니다. 나는 그때 사람 이름을 검색하여 사람의 실행 시간을 검색하기를 바라고 있습니다 (그러면 주자 이름과 시간이 화면에 표시됩니다.) Java에서이 작업을 수행 할 수 있습니까? Thanks Cassy데이터와 관련된 이름을 입력하여 데이터 찾기
여기에 있습니다. 내 코드는 ...입니다
import java.util.Scanner;
public class Trying
{
public static void main (String[] args)
{
int num;
Scanner input= new Scanner (System.in);
System.out.println("******************************************************************* ");
System.out.println("Welcome to Running Race Time Statistical Analysis Application");
System.out.println("******************************************************************* \n");
System.out.println("Please input number of participants (2 to 10)");
num=input.nextInt();
// If the user enters an invalid number... display error message...
while(num<2|| num >10)
{
System.out.println("Error invalid input! Try again! \nPlease input a valid number of participants (2-10)...");
num=input.nextInt();
}
// declare arrays
double resultArray [] = new double [num]; // create result array with new operator
String nameArray [] = new String [num];// create name array with new operator
// Using the num int will ensure that the array holds the number of elements inputed by user
// loop to take in user input for both arrays (name and result)
double count = 0;
for (int i = 0 ; i < nameArray.length ; i++)
{
System.out.println ("Please enter a race participant Name for runner " + (i+1));
nameArray[i] = input.next();
System.out.println ("Please enter a race result (time between 0.00 and 10.00) for runner " + (i+1));
resultArray[i] = input.nextDouble();
count += resultArray[i]; // This count variable is used later to calculate average from total
}
}
}
예, 가능하며 코드가 광범위하게 작동합니다. 그러나이 "병렬 배열"디자인은 대신에'name'과'result' 필드를 가진'Runner' 클래스와'Runner '의 배열 (더 좋으면'List')을 가져야한다는 강력한 지표입니다. '객체. – chrylis
그것의 구현을 기대하고있는 그 이름으로 함수를 검색했습니다 – CassyHiggins
감사합니다 chrylis하지만 그 방법을 잘 모르겠습니다! – CassyHiggins