2007-12-18 10:28:03娃娃♡°
Notebook VI
public class InitArray
{
public static void main(String args[])
{
final int ARRAY_LENGTH = 7;
int array[] = new int[7];
for ( int counter = 0; counter < array.length;counter++)
array[ counter ] = 11+2*counter;
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”);
}
}
{
public static void main(String args[])
{
final int ARRAY_LENGTH = 7;
int array[] = new int[7];
for ( int counter = 0; counter < array.length;counter++)
array[ counter ] = 11+2*counter;
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”);
}
}
上一篇:notebookV
下一篇:notebook VII