# Field Manual for Hackers

## java - Write a program which accept a number ‘N’ and then find the sum of the integer from 1 to 2, then 1 to 3 then 1 to 4 and so forth until it display the sum of integers from 1 to N.

1. import java.util.Scanner;

class Test
{

public static void main(String ar[])
{
int num,sum=0,sumt=0;
System.out.println("Enter Number");
Scanner o= new Scanner(System.in);
num=o.nextInt();

for(int i=1;i<=num;i++){
for(int j=1;j<=i;j++){
sum+=j;
if(j==i)
System.out.printf("%d ",j);
else
System.out.printf("%d + ",j);

}
System.out.printf("= %d",sum);
sumt+=sum;
System.out.println("");
sum=0;
}
System.out.println("Total Sum = "+sumt);

}
}

2. import java.util.Scanner;
class SumofInteger
{
public static void main(String ar[])
{ int N,i,j,Total=0,sum=0;
Scanner scan=new Scanner(System.in);
System.out.println("Enter the Number");
N=scan.nextInt();
for(i=1;i<=N;i++)
{
for(j=1;j<=i;j++)
{
sum=sum+j;

}
System.out.println(i+".cycle sum="+sum);
Total=Total+sum;
sum=0;
System.out.println("");
}
System.out.println("Total Sum="+Total);
}
}

3. import java.util.Scanner;

class Test1
{

public static void main(String ar[])
{

Scanner w=new Scanner(System.in);
int number,sum=1,result=0;
System.out.print("Enter Number");
number=w.nextInt();

for(int i=2;i<=number;i++)
{
System.out.print("1");
for(int j=2;j<=i;j++)
{
System.out.print("+"+j);
sum+=j;
}
result+=sum;
System.out.println("="+sum);
sum=1;
}

System.out.print("The result is: "+result);
}
}

4. import java.util.Scanner;

class serissum
{
public static void main(String ar[])
{
Scanner scan = new Scanner(System.in);
int n;
System.out.println("enter the value upto which sum is required");
n=scan.nextInt();
int sum=0;
for(int i=0;i<=n;i++)
{ sum=0;
for(int j=0;j<=i;j++)
{
sum+=j;
}
System.out.println();
System.out.println("Sum of the given series is "+sum); }
}
}

output:
enter the value upto which sum is required
5

Sum of the given series is 0

Sum of the given series is 1

Sum of the given series is 3

Sum of the given series is 6

Sum of the given series is 10

Sum of the given series is 15

5. package forloop;
import java.util.*;
public class SumInteger
{
public static void main(String args[])
{
int i,j,n,sum=0;
System.out.println("Enter number");
Scanner sc=new Scanner(System.in);
n=sc.nextInt();
for(i=1;i<=n;i++)
{sum=0;
for(j=0;j<=i;j++)
{
sum+=j;
}
System.out.println("Sum of the series is "+sum);
}
}
}

6. import java.util.Scanner;
class Sumupton{
public static void main(String ar[]){
Scanner obj=new Scanner(System.in);
int n,j,i,sum=0;
System.out.println("enter the value of n");
n=obj.nextInt();
for(i=2;i<=n;i++){
for(j=1;j<=i;j++){
sum=sum+j;
}
}
System.out.println("the value of sum is"+sum);
}

}

7. import java.util.Scanner;

class SumOfInteger{

public static void main(String ar[]){

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

for(int i=2;i<=num;i++){

for(int j=1;j<=i;j++){

sum=sum+j;

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

}

}