使用Java储存国家名称及人口

public static void main(String[] args) {
          final int MO = 6;
          String [] hours = new String[MO];
          Scanner keyboard = new Scanner(System.in);
          System.out.println("Please enter the country name and number of people in the country");
          for (int index = 0; index<MO; index++)
          {
              System.out.println("Country name and number of countries:" + (index + 1) + " : ");
              hours[index] = keyboard.nextLine();
          }
          System.out.println("The country name and number of countries you entered are:");
          for(int index = 0; index<MO; index++)
              System.out.println(hours[index]);
       }

可以通过改变MO的数值来实现改变输入的国家的个数,可以让数据更加简洁地呈现出来。

猜你喜欢

转载自blog.csdn.net/qq231062/article/details/120677391