計算機程式設計C組 Week10 回家作業


Problems

Problem Points AC Rate Users
Right-Aligned Number Triangle 10 38.2% 52
Caesar Cipher Encryption 10 48.7% 54
sum of numbers less than 100 20 65.9% 370
score below 60 20 33.8% 304
Arithmetic Sequence 10 56.3% 179
x to -x 10p 49.3% 299
square * hollow 10p 76.5% 230

Comments


  • 0
    scu15156371  commented on Nov. 26, 2026, 3:27 p.m.

    import java.util.Scanner;

    public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt();

        for (int i = 1; i <= n; i++) {
            // Print leading spaces for right alignment
            for (int j = 1; j <= n - i; j++) {
                System.out.print("  ");
            }
    
            // Print numbers from 1 to i
            for (int k = 1; k <= i; k++) {
                if (k > 1) {
                    System.out.print(" ");
                }
                System.out.print(k);
            }
    
            System.out.println();
        }
    
        sc.close();
    }

    }