# Field Manual for Hackers

## java - Write a program to find the sum of N numbers.

1. import java.util.Scanner;

class Test{

public static void main(String ar[])
{

Scanner sc=new Scanner(System.in);
long num,loop=0,sum=0;

System.out.println("Enter Number");
num=sc.nextLong();

while(loop<=num)
{
sum+=loop;
loop++;
}

System.out.println("Sum = "+sum);

}
}

2. import java.util.Scanner;

class Test
{

public static void main(String ar[])
{
int num,sum=0,i=1;
System.out.print("Enter the number: ");
Scanner o= new Scanner(System.in);
num=o.nextInt();

while(i<=num)
{
sum+=i;
i++;
}

System.out.println("The sum is: "+sum);

}
}

3. import java.util.Scanner;

class SumofN
{
public static void main(String ar[])
{
Scanner sc=new Scanner(System.in);
int Number,Number1=0,Total=0;
System.out.println("Enter the Number");
Number=sc.nextInt();

while(Number1<=Number)
{
Total=Total+Number1;
Number1++;
}
System.out.println("Sum of N number= "+Total);
}
}

4. import java.util.Scanner;
class SumN
{
public static void main(String Args[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter the number");
int num=sc.nextInt();
int i=1,sum=0;
while(i<=num)
{
sum+=i;
i++;
}
System.out.println("sum is "+sum);
}
}

5. 18.
import java.util.Scanner;
public class JavaApplication6 {

public static void main(String[] args) {

Scanner obj=new Scanner(System.in);
int num;
num=obj.nextInt();
int sum=0;
for(int i=0;i<num;i++)
{
sum+=i;
}
System.out.println("The sum of N numbers is="+sum);
}
}

6. import java.util.Scanner;

class sumofseries
{
public static void main(String ar[])
{
Scanner scan = new Scanner(System.in);
int n , sum =0;
System.out.println("enter the number upto which sum is needed");
n = scan.nextInt();
int i =0;
while(i <= n)
{
sum += i;
i++;
}
System.out.println("the sum upto given number is : " +sum);

}

}

7. import java.util.Scanner;
class Numsum{
public static void main(String ar[]){
Scanner obj=new Scanner(System.in);
int num,i=1,sum=0;
System.out.println("enter the number");
num=obj.nextInt();
while(i!=num+1){
sum=sum+i;
i++;
}
System.out.println("the sum of numbers is"+sum);
}
}

8. import java.util.Scanner;
class Sum{
public static void main(String ar[]){
int number,i=0,sum=0;
Scanner scan=new Scanner(System.in);
System.out.println("ENTER A NUMBERs");
number=scan.nextInt();
while(i<=number){
sum=sum+i;
i++;
}
System.out.println("sum ="+sum);
}
}

9. import java.util.Scanner;
class Sum{
public static void main(String ar[]){

int n,i=1,sum=0;
Scanner scan=new Scanner(System.in);
System.out.println("Enter the number:");
n=scan.nextInt();
while(i<=n){
sum=sum+i;
i++;
}
System.out.println("The sum of n numbers is:"+sum);
}
}

10. import java.util.*;
class Sum1{
public static void main(String ar[]){
Scanner s=new Scanner(System.in);
int n,i=1,sum=0;
System.out.print("enter the no. of terms you want sum of: ");
n=s.nextInt();
while(i<=n)
{ sum+=i;
i++;
}
System.out.print("sum: "+sum);
}
}

11. import java.util.Scanner;

class Sum{

public static void main(String ar[]){

Scanner scan=new Scanner(System.in);
int sum=0,i=0,num;
System.out.println("Enter number");
num=scan.nextInt();
while(i<=num){
sum=sum+i;
i++;

}
System.out.println("Sum="+sum);

}
}