码迷,mamicode.com
首页 > 其他好文 > 详细

HW6.12

时间:2016-08-25 23:26:19      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 

 1 import java.util.Scanner;
 2 
 3 public class Solution
 4 {
 5     public static void main(String[] args)
 6     {
 7         Scanner input = new Scanner(System.in);
 8         System.out.print("Enter the count of numbers: ");
 9         int count = input.nextInt();
10         int[] number = new int[count];
11 
12         for(int i = 0; i < count; i++)
13             number[i] = input.nextInt();
14 
15         input.close();
16 
17         for(int i: number)
18             System.out.print(i + " ");
19         System.out.println();
20 
21         int[] anotherNumber = reverse(number);
22         for(int i = 0; i < anotherNumber.length; i++)
23             System.out.print(anotherNumber[i] + " ");
24     }
25 
26     public static int[] reverse(int[] array)
27     {
28         int temp;
29         for(int i = 0; i < array.length / 2; i++)
30         {
31             temp = array[i];
32             array[i] = array[array.length - 1 - i];
33             array[array.length - 1 - i] = temp;
34         }
35         return array;
36     }
37 }

 

HW6.12

标签:

原文地址:http://www.cnblogs.com/wood-python/p/5808415.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!