就是愛分享
隨着網際網路蓬勃發展和隨身碟的普遍流行
電腦病毒從早期開玩笑、破壞系統等行為
進化到盜取個人資料的木馬程式
因此帳密的設定是防範被盜用的第一步驟
通常都會建議採用複雜性密碼
也就是八個字以上,由數字、英文與字母大小寫所組成

這個程式是個簡單的密碼安全檢查程式


public class For2 {

public static void main(String[] args) {
String pw = "ab12";
boolean hasNumber = false;
boolean hasLetter = false;

for (int i=0;i char c = pw.charAt(i);
int n = c;
if (n >= 48 & n <= 57){
System.out.println("是數字");
hasNumber = true;
}
else if (n >=65 & n <= 90){
System.out.println("是文字");
hasLetter = true;
}
else if (n >=97 & n <= 122){
System.out.println("是文字");
hasLetter = true;
}
}

if (hasNumber & hasLetter == true )
System.out.println("密碼安全");
else System.out.println("密碼不安全喔");
}
}

另一個程式是條件判斷式的程式練習 - BMI指數公式計算

import javax.swing.JOptionPane;

public class BMI {
public static void main(String[] args) {
float h,w,b;
String s = JOptionPane.showInputDialog("身高(公分):");
h = Integer.parseInt(s) / 100f;
s = JOptionPane.showInputDialog("體重(公斤):");
w = Integer.parseInt(s);

b = w/(h*h);
b = b + 0.005f;
b = b * 100;
b = (int)b;
b = b /100.0f;

JOptionPane.showMessageDialog(null, "身高 " + h * 100 + "公分 ; 體重 " +w + "公斤" +
" ; BMI值是 " +b);

if (b < 18.5){
System.out.print("過輕");
}
else if (b >= 18.5 & b < 24){
System.out.print("正常");
}
else if (b >24 & b < 27){
System.out.print("過重");
}
else if (b >27 & b < 30){
System.out.print("輕度肥胖");
}
else if (b > 30 & b < 35){
System.out.print("中度肥胖");
}
else {
System.out.print("重度肥胖");
}
System.out.println(" - BMI 關心您 ^^");
}
}

最後一個是最基本的迴圈程式練習 - 9x9乘法表

public class Math9 {

public static void main(String[] args) {
for(int m=1;m<10;m++){
for(int n=2;n<10;n++){
System.out.print(n+"*"+m+"="+m*n+"\t");
}
System.out.println();
}
}
}

標籤: | edit post
0 Responses