栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

应该提示用户输入几个整数,并将它们存储到数组,然后按向前和向后的顺序打印这些整数。

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

应该提示用户输入几个整数,并将它们存储到数组,然后按向前和向后的顺序打印这些整数。

public static void main(String[] args) {

      final int EMPLOYEES = 3;
      int[] hours = new int[EMPLOYEES];
      Scanner keyboard = new Scanner(System.in);
      System.out.println("Enter the hours worked by"+ " " + EMPLOYEES + " " + "employees.");
      System.out.print("Employee 1:");
      hours[0] = keyboard.nextInt();
      System.out.print("Employee 2:");
      hours[1] = keyboard.nextInt();
      System.out.print("Employee 3:");
      hours[2] = keyboard.nextInt();
      System.out.println("The hours you enter are:");
      System.out.println(hours[0]);
      System.out.println(hours[1]);
      System.out.println(hours[2]);
    }

我们也可以使用循环来实现这个程序的运行:

public static void main(String[] args) {
        
        final int EMPLOYEES = 6;
          int [] hours = new int[EMPLOYEES];
          Scanner keyboard = new Scanner(System.in);
          System.out.println("Country name and population");
          for (int index = 0; index           {
              System.out.print("Employee" + (index + 1) + " : ");
              hours[index] = keyboard.nextInt();
          }
          System.out.print("The hours you entered are:");
          for(int index = 0; index               System.out.println(hours[index]);
    }
 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/301027.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号