-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsecutive.java
More file actions
36 lines (34 loc) · 897 Bytes
/
consecutive.java
File metadata and controls
36 lines (34 loc) · 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import java.util.*;
public class consecutive
{
public static void main(String args[])
{
int i,j,k,n,x,s;
Scanner as = new Scanner(System.in);
System.out.println("\t \t CONSECUTIVE ADDITION \n\n");
System.out.print("Enter a number:");
n=as.nextInt();
System.out.println("\nTHE RESULT:\n");
for(i=1;i<=(n/2 +1);i++)
{
s=x=0;
k=(n/2 +1);
for(j=i;j<=k;j++)
{
if(s<=n && x==0)
s+=j;
if(s==n && x==0)
{
k=j-1;
j=i-1;
x=1;
continue;
}
if(x==1)
System.out.print(j+"+");
}
if(x==1)
System.out.println(j+"="+n);
}
}
}