a plus aa plus aaa (simple version)


Submit solution

Points: 10 (partial)
Time limit: 5.0s
Memory limit: 256M

Author:
Problem type
Allowed languages
Java 19, Java 8

題目說明

輸入一個正整數(a)

求s=a+aa+aaa的值。假設a=2,則輸出結果的形式如:2+22+222=246;

輸入限制: a為介於0~9之間的正整數

輸入

正整數a

輸出

a+aa+aaa= (如上形式所示)

sample input1

1

sample output1

1+11+111=123

sample input2

3

sample output2

3+33+333=369

Comments


  • 0
    scu12115149  commented on Oct. 8, 2025, 12:23 a.m.

    import java.util.Scanner; public class HW_3_2 {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc = new Scanner(System.in);
    
        System.out.println("正整數a:");
        int a=sc.nextInt();
    
    
    
        if (a <= 0 ){
        System.out.println("輸入錯誤");}
    
        if (a >= 9 ){
            System.out.println("輸入錯誤 ");}
    
    
        int s=a*(1+11+111);
    
        System.out.println(a+"+"+(a*10+a)+"+"+(a*100+a*10+a)+"="+s);