close

package p01;

import java.util.Scanner;

public class ForLoop {

    public static void main(String[] args) {
        //for迴圈應用
        Scanner sc = new Scanner(System.in);

        System.out.println("請輸入X(1~5)");
        int myX = sc.nextInt();
        System.out.println("請輸入Y(1~10)");
        int myY = sc.nextInt();

        for (int x = 1; x <= 5; x++) {
            for (int y = 1; y <= 10; y++) {
                /*if (x == myX && y == myY) {
                    System.out.print("X ");

                } else {
                    System.out.print("o ");
                }
            }
            System.out.println();
        }
        使用條件式?來簡化if else if*/

                //        x等於myX而且y等於myY   成立輸入x  不成立輸入o
                System.out.print(x == myX && y == myY ? "x" : "o");
            }
            System.out.println();
        }
    }
}

arrow
arrow
    文章標籤
    程式語言 HomeWork
    全站熱搜

    蛋餅Brook 發表在 痞客邦 留言(0) 人氣()