자바

[JAVA] 출력 형식

코딩하는둥이 2022. 11. 26. 20:58

1.  7 + 23 =30 을 출력하시오

     :  세 정수형 변수를 선언한고 차례로 7,23,30 넣어 덧셈식을 출력하시오

public class Main {
    public static void main(String[] args) {
        int a = 7;
        int b= 23;
        int c = 30;

        System.out.println(a + " + " + b + " = " + c);
 
    }
}

2. 3...C 을 출력하시오

    : 변수 a, b에 각각 3, 'C'을 넣어주고, 출력 형식에 알맞게 출력하는 프로그램을 작성하세요.

public class Main {
    public static void main(String[] args) {
        int a = 3;
        char b = 'C';

        System.out.println(a+"..."+b);

    }
}

3. C!.....!3 을 출력하시오

    : b, a의 값을 순서대로 출력하되 사이에 "!.....!"를 포함합니다.

 

public class Main {
    public static void main(String[] args) {
        int a = 3;
        char b = 'C';

        System.out.println(b+"!.....!"+a);

    }
}

 

4.1->2->C을 출력하시오

    : 변수 a, b, c에 각각 1, 2, 'C'을 넣어주고, 출력 형식에 알맞게 출력하는 프로그램을 작성하세요.

public class Main {
    public static void main(String[] args) {
        int a = 1;
        int b = 2;
        char c = 'C';


        System.out.println(a+"->"+b+"->"+c);

    }
}