2007-12-18 11:01:57娃娃♡°

notebook VII

import java.util.Random;
public class InitArray
{
public static void main(String args[])
{
int array[] = {1,8,5};
System.out.printf("%s%8sn","Index","Value");
for ( int counter = 0; counter < array.length;counter++)
System.out.printf("%5d%8dn",counter,array[ counter]) ;//印出7個陣列11~23
int total = 0;
for ( int counter = 0; counter < array.length;counter++)
total +=array[counter];
System.out.printf("nTolal= %dn",total);//陣列的總合
for ( int counter = 0; counter < array.length;counter++){
System.out.printf("n%d:",counter);
for(int i=0;i< array[counter];i++)
System.out.printf("%c",’*’);
}//印出長條圖
System.out.printf("n");
Random r= new Random();
for(int counter= 0; counter<100; counter++)
array[r.nextInt(array.length)]++;
for(int counter= 0; counter< array.length; counter++)
System.out.printf("%5d%8dn", counter, array[counter]);//
}
}



*******************************************************
Index Value
0 1
1 8
2 5

Tolal= 14

上一篇:Notebook VI

下一篇:NotebookVIII