Page 413 - Computer science 868 Class 12
P. 413
45 public static void main()
46 { Note ob=new Note(); // object creation
47 ob.accept();
48 ob.print();
49 }
50 }
The output of the preceding program is as follows:
Program 6 A positive natural number can be represented by sum of consecutive natural numbers as
follows. Say Number = 27
27 = 2 + 3 + 4 + 5 + 6 + 7
27 = 8 + 9 + 10
27 = 13 + 14
Write a program to input any positive natural number and print the possible consecutive
natural number which when added give that number. [ISC Practical 2006]
1 import java.util.*;
2 class Consicutive
3 { int num,sum;
4 Consicutive() // default constructor
5 { num=0;sum=0;}
6
7 void accept() // Input number
8 { Scanner sc=new Scanner(System.in);
9 System.out.println("Enter number");
10 num=sc.nextInt();
11 }
12 int calsum(int x)
411
Recursion 411

