Skip to content
This repository was archived by the owner on Aug 6, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions SsccJava3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import java.util.ArrayList;
import java.util.Scanner;

public class SsccJava3 {
public static void main(String[] args) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Car의 정보들(이름, 스피드 등등...)을 담을 수 있는 Car 클래스를 정의하여 코드를 다시 작성해주세요.

Scanner scanner = new Scanner(System.in);
/*String name = scanner.nextLine();
int count = scanner.nextInt();

System.out.println(name);
System.out.println(count);*/

System.out.println("자동차의 개수를 입력하세요.");
int count = scanner.nextInt();
//int carSpeed;
//String carName;
ArrayList carSpeed = new ArrayList();
ArrayList<String> carName = new ArrayList<>();

for (int i = 1; i <= count; i++) {
System.out.println(i + "번째 자동차의 스피드를 입력하세요.");
int speed = scanner.nextInt();
scanner.nextLine();
System.out.println(i + "번째 자동차의 이름을 입력하세요.");
String name = scanner.nextLine();
carSpeed.add(speed);
carName.add(name);
}

scanner.close();

System.out.println("\n-----경기 참가자 소개-----");
for (int i = 1; i <= count; i++) {
System.out.println("스피드는 " + carSpeed.get(i-1) + "이고, 이름은 " + carName.get(i-1) + "입니다.");
}
}
}