Wrong code, bug or interpretation fails? (Help me --> Java While test)
It's the instruction: ============ Your math teacher asked you to calculate the sum of the numbers 1 to N, where N is a given number. -- Task: Take an integer N from input and output the sum of the numbers 1 to N, inclusive. Sample Input: 10 Sample Output: 55 It's my code: ============= import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int x = 0; do{ x++; } while(x < n); System.out.println(x); } } It's the result: ============ Input: 4 Your Output: 4 Expected Output: 10 I really have no idea about how to receive the "Expected output", it's not a VAR... It's an aleatory number.