Biblioteca Java - Blame information for rev 39
Subversion Repositories:
Rev | Author | Line No. | Line |
---|---|---|---|
39 | mihai | 1 | package introducere.java.controlflow; |
4 | mihai | 2 | |
3 | |||
4 | public class ForStructure { | ||
5 | |||
6 | /** | ||
7 | * Generate an array of random int numbers. | ||
8 | * @return | ||
9 | */ | ||
10 | static int[] generateArray(){ | ||
11 | int size = (int)Math.round(Math.random()*15); | ||
12 | int[] a = new int[size]; | ||
13 | for(int i=0;i<a.length;i++){ | ||
14 | a[i] = (int)Math.round(Math.random()*100); | ||
15 | } | ||
16 | return a; | ||
17 | } | ||
18 | |||
19 | /** | ||
20 | * Display the content of an array. | ||
21 | * @param a | ||
22 | */ | ||
23 | static void displayArray(int[] a){ | ||
24 | for (int i = a.length; --i>=0; ) | ||
25 | { | ||
26 | System.out.print("a["+i+"]="+a[i]+" "); | ||
27 | } | ||
28 | System.out.println(); | ||
29 | } | ||
30 | |||
31 | public static void main(String[] args) { | ||
32 | int a[]; | ||
33 | a = generateArray(); | ||
34 | displayArray(a); | ||
35 | } | ||
36 | } |