今天上了JAVA的第2講課,上到一半感覺那些data type在C++都學過的,所以就先開溜了~出來居然看到了大雨和大太陽在同一時間進行^_^
回來把作業做完了,但第2題搞了半天老是越界問題,結果出在自己沒仔細.看來programming的時候千萬不要粗心啊^_^大家繼續努力吧~
/*
輸出前10個的自然數的平方
Shawn
CityPW@copyright
*/
class square
{
static int i,v;
square()
{
System.out.println("歡迎計算平方!");
show();
}
void show()
{
for(i=1;i<=10;i++)
{
System.out.println(i*i); //System.out.println就好比C++裡的cout輸出資料流
}
}
public static void main(String[] args) //由於main只能有一個所以要聲明為public static
{
square s=new square();
}
}
/*
排序的
Shawn
CityPW@copyright
*/
class test
{
static int i,j,temp;
test(){System.out.println("開始排序");}
void bubblesort(int[] a)
{
//用一個冒泡泡
for(i=0;i<a.length/3;i++)
{
for(j=0;j<a.length-1;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
}
public static void main(String[] args)
{
int[] arrayOfInts={32,87,3,589,12,1076,2000,8,622,127};
test t=new test();
t.bubblesort(arrayOfInts);
for(int i=0;i<arrayOfInts.length;i++) //列印出結果
System.out.print(" "+arrayOfInts[i]);
}
}