반복문 안에서 계산 결과를 문자열로 조합해 출력할 수 있습니다.
int price = 1500; for (int i = 1; i <= 3; i++) { System.out.println(i + "개 = " + price * i + "원"); }
+가 왼쪽부터 차례로 처리되므로, 문자열이 먼저 오면 그 뒤는 전부 결합이 됩니다.
+
"3 x 1 = 3" 부터 "3 x 3 = 9" 까지 출력하세요
public class Main { public static void main(String[] args) { int dan = 3; // "3 x 1 = 3" 부터 "3 x 3 = 9" 까지 출력하세요 } }