I cant figure out how to add the values after it spits out the numbers. it says:
Number: 5 // I typed 5
1 2 3 4 5
The sum is.
So i need to add those number 1 2 3 4 5 but cant figure out how.
import java.util.Scanner
public class AddingValuesWithAForLoop
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
System.out.println( " \n" );
System.out.println( "Number: " );
int number = keyboard.nextInt();
int sum = 0;
for (int run=1; run<=number; run=run+1)
{
System.out.print( run + " " );
sum = sum + 1 ;
}
System.out.println( "The sum is . " );
}
}