q738...@yahoo.com.tw
unread,Dec 11, 2010, 6:49:56 PM12/11/10Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to EnJoyJava
-----------------------------------第一
題-----------------------------------
import java.util.*;
public class example {
public static void main(String[] args) {
String password = "";
String keyin = "";
Scanner in = new Scanner(System.in);
System.out.println("請輸入你所想要設定的密碼");
password = in.next();
for (int i=0; i<3; i++) {
System.out.println("請輸入你所設定的密碼");
keyin = in.next();
if (keyin.equals(password))
System.out.println("密碼正確");
else {
System.out.println("密碼錯誤");
break;
}
if (i == 2) {
System.out.println("密碼錯誤次數已達三次,程式結束");
}
}
}
}
-----------------------------------第二
題-----------------------------------
import java.util.*;
public class example {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String[] keyin = {","};
String bingonumber = "1,2,3,4,5,6";
String[] bna = bingonumber.split(",");
System.out.println("請輸入6個1~49的號碼並用「,」作為分隔");
keyin = in.next().split(",");
Arrays.sort(keyin);
Arrays.sort(bna);
int bn = 0;
for (int i=0; i<6; i++) {
for (int j=0; j<6; j++) {
if (keyin[i].equals(bna[j])) {
bn++;
break;
}
}
}
if (bn == 6)
System.out.println("恭喜你中頭獎");
else
System.out.println("你中了"+bn+"個號碼");
}
}
-----------------------------------第三
題-----------------------------------
import java.util.*;
public class example {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("請輸入你的身高");
int keyin = in.nextInt();
if (keyin < 120)
System.out.println("120公分以下免費");
else if (keyin > 119 && keyin < 150)
System.out.println("120~150公分半價");
else if (keyin > 149)
System.out.println("150公分以上全票");
}
}
-----------------------------------第四
題-----------------------------------
import java.util.*;
public class example {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("請輸入繩索長度");
int rope = in.nextInt();
int count = 0;
while (rope > 19) {
rope -= 20;
count++;
}
System.out.println("共要對折"+count+"次才會小於20公分");
}
}