*****Solved it myself, thanks for help*****

Hey there,

I've got a program which I need to test whether an integer n is the exact sum of k consecutive integer numbers starting from 1.

eg. 6 is 1 + 2 + 3 and therefore k = 3 and if I put in 4 then it returns false. But what I've only able to achieve so far is to get the program to add numbers 1 to n together, so if I enter 6 I get 21 because 1 + 2 + 3 + 4 + 5 + 6 = 21, but this isn't what I need the program to do. :/ I'm kinda stuck, I've tried a few other things but they aren't working.

import java.util.Scanner; public class ExactSum { /** * @param args */ public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); System.out.println("Type an integer:"); int n = keyboard.nextInt(); System.out.println("The number "+n+" is not an exact sum"); } else {System.out.println("The number "+n+" is the sum of integers from 1 to "+k+" "); } } }

Any help is appreciated!