숫자를 인쇄 할 때와 같은 방식으로 숫자를 함께 추가하는 방법은 무엇입니까?함께 인쇄하는 방법으로 숫자를 함께 추가하는 방법 (System.out.println (numbers)); 숫자 ++;
System.out.println(numbers);
numbers++;
이렇게 인쇄됩니다.
1
2
3
4
등 전 1 + 2 + 3 + 4
로 함께 추가 얼마나
여기이 질문에 내 현재 코드입니다. 이것은 제가 헬싱키 대학교에서 MOOC를 위해 연습하고있는 운동입니다. 저는 미국에 살기 때문에 8 시간의 차이 때문에 도움을 요청하기가 어렵습니다.
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
System.out.print("Until What?:");
// the user inputs a number here
int blockExe = 1;
// the blockExe variable is supposed to store a count of how many times the
// block has been executed which i belive should be limited to the user input
int userIn = Integer.parseInt(reader.nextLine());
int sum = userIn + blockExe;
// i am supposed to add the number of block executions the user input
// each time adding 1 to the execution so 1+2+3
// then printing the sum of those numbers
while (blockExe <= userIn) {
blockExe += 1;
if (blockExe + userIn == sum) {
break;
}
}
System.out.println("Sum is:" +sum);
}
은}
샘플 입력은 무엇이며 어떤 출력을 얻었으며 어떤 출력이 필요합니까? – anirudh
과정에 대한 테스트 러너 두 부정적인 양수를 테스트합니다, 그래서 첫 번째 샘플 입력 6 출력 4 그리고 6이 필요하므로 1 + 2 + 3 = 6으로 계산해야합니다 –