bigger than what?


Submit solution

Points: 50
Time limit: 1.0s
Memory limit: 256M

Authors:
Problem type
Allowed languages
Java 19, Java 8

題目說明

使用者先輸入十個整數於一陣列中,再輸入一整數n,寫一個函式將陣列中大於n的回傳true,反之回傳false於一字串中,最後輸出

public class MyProgram {
    public static void main(String[] args) {
        /*
        * your code
        */
        String yourans = yourfunc(yourarray, endnum);
        /*
        * your answer
        */
    }
    public static String yourfunc(int[] yourarray, int endnum) {
        /*
        * your code
        */
        return youranswer;
    }
}
輸入限制 整數

輸入

十個整數與一整數n

輸出

字串

測試資料1 輸入

1 2 3 4 5 5 4 3 2 1 2

測試資料1 輸出

false false true true true true true true false false

Comments


  • 0
    scu09156238  commented on April 12, 2024, 3:33 p.m.

    題解

    import java.util.Scanner;
    
    public class t04112 {
    
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            Scanner in = new Scanner(System.in);
            int[] a = new int[10];
            for (int i = 0; i < 10; i++) {
                a[i] = in.nextInt();
            }
            int e = in.nextInt();
            in.close();
            System.out.print(func(a, e));
    
        }
    
        public static String func(int[] a, int e) {
            String r = "";
            for (int n : a) {
                if (n <= e) {
                    r += "false ";
                } else {
                    r += "true ";
                }
            }
            return r;
        }
    
    }