在這裏,我試圖從用戶獲得兩個鍵盤輸入到一個單一的數組索引位置。如何使用循環將鍵盤輸入值放入數組中?
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package tour;
import java.util.Scanner;
import tour.City;
/**
*
* @author dp
*/
public class Tour {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
City[] city = new City[9];
Scanner in = new Scanner(System.in);
for(int i=0;i<city.length;i++)
{
int no = in.nextInt();
String name = in.nextLine();
city[i]= new City(no,name);
}
}
}
我對java很陌生,不知道如何解決這個問題。
問題解決了。非常感謝! – Punya