all questions for ex7_8

0 views
Skip to first unread message
Message has been deleted
Message has been deleted

Steven_Tian

unread,
Nov 3, 2010, 11:47:03 PM11/3/10
to Good Ideas
import java.io.*;

public class ex6_8 {
public static void main(String[] argv) throws IOException {
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
int fails=0;
int pass=0;
do{
System.out.println("請輸入四位整數密碼,並以逗點隔開,ex:1,2,3,4:");
String str1 = br.readLine();
String [] srt1s=str1.split(",");
pass=srt1s.length;
System.out.println("請再一次輸入密碼:");
String str2 = br.readLine();
String [] str2s=str2.split(",");
for(int i=0;i<srt1s.length;i++){
if(!srt1s[i].equalsIgnoreCase(str2s[i])){
fails++;
break;
}else{
pass--;
}
}
if(pass==0){
System.out.println("Right password");
break;
}

}while(fails<3);
if(fails==3){
System.out.println("wrong password");
}

}
}

-------------
public class ex7_8 {
public static void main(String[] argv) {


String [] numbers=argv[0].split(",");//請輸入欲排序的數列,並以逗點隔開,ex:1,2,3,4:;
int[] ary = new int[numbers.length]; // 依照參數個數來宣告陣列大小
for (int a = 0; a < numbers.length; a++) {
ary[a] = Integer.parseInt(numbers[a]); // 將文字轉成數字放到要排序的陣列
}
for(int j=0;j<ary.length;j++){
for(int i=0;i<ary.length-1;i++){
int temp=ary[i];
if(temp>ary[i+1]){
ary[i]=ary[i+1];
ary[i+1]=temp;
j=i;
break;
}
}
}

for (int n = 0; n < ary.length; n++) {
System.out.println("" + ary[n]);
}
}
}

Steven_Tian

unread,
Nov 4, 2010, 3:03:26 AM11/4/10
to Good Ideas
public class ex7_8 {
public static void main(String[] argv) {
int[] ary = new int[argv.length]; // 依照參數個數來宣告陣列大小
for (int a = 0; a < argv.length; a++) {
ary[a] = Integer.parseInt(argv[a]); // 將文字轉成數字放到要排序的陣列

Gensi

unread,
Nov 4, 2010, 2:33:55 PM11/4/10
to Good Ideas

嗯嗯,大致上OK了,感謝您的幫忙!!
第一題我自己慢慢解就好了,應該不是很難...

謝謝

Reply all
Reply to author
Forward
0 new messages