마지막 println에 문제가 있습니다. 이전 문자열이 인쇄 된 횟수를 인쇄하고 모든 숫자를 함께 추가하기를 원합니다. 따라서 사용자가 "3"을 입력하면 3 번 인쇄하고 6 개의 숫자를 합쳐 6을 얻습니다. 내가 어떻게 할 수 있는지 아는 사람 있습니까? 아니면 내가 뭘 잘못하고있는거야?Java 메서드에서 while 루프를 사용하고 추가 기능을 인쇄하는 방법은 무엇입니까?
import java.util.Scanner;
public class LoveCS {
public static void main(String[] args) {
int limit;
Scanner scan = new Scanner(System.in);
System.out.println("How many times should the string be printed? ");
limit = scan.nextInt();
int count = 1;
while (count <= limit){
System.out.println(+count+"I love hot chocolate!!");
count++;
}
sum+=limit;
System.out.println("Java printed this message: "+ limit+ " times." + "The sum of the numbers from 1 to " + (count-1) + " is " sum);
}
}
신 댕 형식 미안하지만 난 아주 경험입니다 – hvgotcodes