java程式註解 !!急需!!請幫幫忙!!!!

我需要以下程式碼的"每一行"註解

請大大幫忙 感謝您

___________________________________________________

import java.util.*;

public class A0918 {

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);

System.out.print("請輸入三個字串,每個字串中間以空白隔開: ");

String[] ary1 = scan.nextLine().split(" ");

System.out.print("請再輸入一次: ");

String[] ary2 = scan.nextLine().split(" ");

boolean isSame = true;

for (int i = 0; i < 3 && i < ary1.length && i < ary2.length; i++) {

if (!ary1[i].equalsIgnoreCase(ary2[i])) {

isSame = false;

break;

}

}

if (isSame) System.out.println("兩次輸入相同");

else System.out.println("兩次輸入不相同");

}

}

1 Answer

Rating
  • 7 years ago
    Favorite Answer

    import java.util.*;

    public class A0918 {

    public static void main(String[] args) {

    Scanner scan = new Scanner(System.in); //準備接受輸入

    System.out.print("請輸入三個字串,每個字串中間以空白隔開: "); //顯示: 請輸入三個字串,每個字串中間以空白隔開:

    String[] ary1 = scan.nextLine().split(" "); //將輸入字串以空格區隔出來, 存入ary1 字串列

    System.out.print("請再輸入一次: "); //要求再輸入一次

    String[] ary2 = scan.nextLine().split(" "); //將輸入字串以空格區隔出來, 存入ary1 字串列

    boolean isSame = true; //定義布林變數

    for (int i = 0; i < 3 && i < ary1.length && i < ary2.length; i++) { //準備檢查輸入的單字

    if (!ary1[i].equalsIgnoreCase(ary2[i])) { //如果兩次輸入的單字不相同

    isSame = false; //布林變數則等於 false

    break; //離開 for loop

    }

    }

    if (isSame) System.out.println("兩次輸入相同"); // 如國布林變數為 true(真), 顯示 兩次輸入相同

    else System.out.println("兩次輸入不相同"); //否則顯示 兩次輸入不相同

    }

    }

    P.S. You should study hard, other wise you need consider to transfer your major

    • Commenter avatarLogin to reply the answers
Still have questions? Get your answers by asking now.