/*1.運用一維數組設計一個可計算多個數的平均的程序*/
// public static int i=0;//for循環計數變量
// public static float Number[] = new float[20];//存儲數據的浮點數數組
// public static float Summary;//數據總和變量
// public static float Average;//數據平均變量
// public static void main(String[] args) {
// TODO Auto-generated method stub
// System.out.println("HELLO JAVA...");
// Summary = 0;//數據總和變量初值化
// System.out.println("Please input the number of data:");//讀入最大可輸入數據個數
// ConsoleReader console = new ConsoleReader(System.in);
// int Max = console.readInt();
// System.out.println("");
//
// if(Max <= 20){//決定最大可輸入數
// for(i=0;i<Max;i++){
// System.out.println("Please input a number:");
// Number[i] = (float)console.readDouble();
// Summary += Number[i];
// }
// Average = Summary/Max;//平均值=總和/個數
// System.out.println("The average is:"+Average);
// }else{//如果輸入數字超出范圍
// System.out.println("Please input a number less than 20.");
// }
// }
/*2.運用一維數組設計一個簡易的員工工資管理系統(具有查詢與修改功能)*/
/*
* public static int[] Employee={27000,27111,27222,27333,27444,27555,27666,27777,27888,27999};
public static int Index;//數組下標變量
public static int NewSalary;//修改後工資變量
public static int Selection;//用戶選項變量
boolean Flag = false;
while(!Flag){
//用戶菜單
System.out.println("++++++++++++++++++++++++++++++++++++++");
System.out.println("1.Display employee salary =");
System.out.println("2.Modify employee salary =");
System.out.println("3.Quit");
System.out.println("++++++++++++++++++++++++++++++++++++++");
System.out.println("Please input your choose:");//讀取用戶選項
ConsoleReader console = new ConsoleReader(System.in);
int Selection = console.readInt();
if(Selection ==1 || Selection ==2){
System.out.println("Please input the employee number:");//讀取員工編號
Index = console.readInt();
if(Index <10){
System.out.println("**Employee Number is"+Index);
System.out.println("**The Salary is"+Employee[Index]);
}else{
System.out.println("##The error employee number!");
Flag = true;
}
}
switch(Selection){
case 1:
break;
case 2:
System.out.println("**Please enter new Salary:");//修改後的員工工資
NewSalary = console.readInt();
System.out.println("");
Employee[Index]=NewSalary;
break;
case 3:
Flag = true;
System.out.println("You leave from System.");
break;
}
System.out.println("");
}
*/
/*3.運用一維數組設計一個可存儲員工工資讓用戶輸入工資,然後輸出員工編號的程序*/
/*
public static int[] Employee={27000,27111,27222,27333,27444,27555,27666,27777,27888,27999};//預設10筆資料
public static int Salary;//用戶輸入工資變量
public static int Counter=0;//數據計數變量
int i;//for循環計數變量
System.out.println("Please input the employee salary:");
ConsoleReader console = new ConsoleReader(System.in);
Salary = console.readInt();
for(i=0;i<10;i++){//數組遍歷
if(Salary == Employee[i]){
System.out.println("Number"+i+"Employee's salary is"+Salary+"!");
Counter++;
}
}
if(Counter == 0){
System.out.println("No employee's salary is"+Salary+"!!");
}else{
System.out.println("Have"+Counter+"employee salary is"+Salary+"!!");
}
*/
/*4.設計一個可容納40位數的求n!的程序*/
/*
int Data[] = new int[40];
int Digit;
int i,j,r,k;
int N;
for(i=1;i<40;i++){
Data[i]=0;
}
Data[0]=1;
Data[1]=1;
Digit = 1;
System.out.println("Enter a number what you want to calculus:");
ConsoleReader console = new ConsoleReader(System.in);
N = console.readInt();
for(i=1;i<N+1;i++){
for(j=1;j<Digit+1;j++){
Data[j]*=i;
}
for(j=1;j<Digit+1;j++){
if(Data[j]>10){
for(r=1;r<Digit+1;r++){
if(Data[Digit]>10){
Digit ++;
}
Data[r+1] += Data[r]/10;
Data[r]=Data[r]%10;
}
}
}
System.out.print(i+"!=");
for(k=Digit;k>0;k--){
System.out.print(Data[k]);
}
System.out.println("");
}
*/
/*設計從二維轉一維數組(行轉列或列轉行)*/
/*
int[][] Data = {{1,2,3},{4,5,6},{7,8,9},{0,10,11}};
int RowData[] = new int[12];//存儲以行為主的數組
int ColData[] = new int[12];//存儲以列為主的數組
int i,j;
System.out.println("The Data of two dimensional array:");
for(i=0;i<4;i++){
for(j=0;j<3;j++){
System.out.println(" "+Data[i][j]+" ");
System.out.println("");
}
}
for(i=0;i<4;i++){
for(j=0;j<3;j++){
RowData[i*3+j] = Data[i][j];
}
}
System.out.println("");
System.out.println("The Row major Martrix:");
for(i=0;i<12;i++){
System.out.println(" "+RowData[i]+" ");
}
System.out.println("");
for(i=0;i<4;i++){
for(j=0;j<3;j++){
ColData[j*4+i] = Data[i][j];
}
}
System.out.println("");
System.out.println("The Column Major Matrix:");
for(i=0;i<12;i++){
System.out.println(" "+ColData[i]+" ");
}
System.out.println("");
*/
/*特殊的數組(稀疏數組)*/
/*
*int [][] Data = {{0,0,0,0,0,0,0}
,{0,3,0,0,0,0,0}
,{0,0,0,0,0,0,0}
,{1,4,0,0,0,0,0}
,{0,0,7,0,0,0,0}
,{0,0,0,0,0,5,0}
,{0,0,0,0,0,0,0}
,{0,0,0,0,0,0,0}
,{0,0,0,0,0,0,0}
,{0,0,0,0,0,0,0}};
int CompressData[][] = new int[10][3];//存儲壓縮後數據的數組
int Index;//壓縮數組的下標
int i,j;
Index = 0;
System.out.println("Two dimensional sparse array:");
for(i=0;i<9;i++){
for(j=0;j<7;j++){
System.out.print(" "+Data[i][j]+" ");
}
System.out.println("");
}
for(i=0;i<9;i++){
for(j=0;j<7;j++){
if(Data[i][j] != 0){
Index++;//增加下標值
CompressData [Index][0] = i;//元素行位置
CompressData [Index][1] = j;//元素列位置
CompressData [Index][2] = Data[i][j];//元素值
}
}
}
CompressData [0][0] = 9;//原數組的行數
CompressData [0][1] = 7;//原數組的列數
CompressData [0][2] = Index;//使用元素個數
System.out.println("Two dimensional compress array:");
for(i=0;i<Index;i++){
for(j=0;j<3;j++){
System.out.print(" "+CompressData[i][j]+" ");
}
System.out.println("");
}
*/