Wednesday, February 23, 2011

Program On Different Combination Of Number In BlueJ


import java.io.*;
class NumberCombination
{
 int n,i,sum,j,flag;
 BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
 public void take()throws Exception
 {
  System.out.println("\nEnter the number:");
  n=Integer.parseInt(br.readLine());
  for(i=n;I >0;i--)
  {
   sum=0;
   flag=0;
   for(j=i;j>0;j--)
   {
    sum=sum+j;
    if(sum >n)
    {
     flag=1;
     break;
     }
   System.out.print(j+" ");
   }
   if(flag==0)
   {
    for(;sum< n;sum++)
    System.out.print(1+" ");
    }
else if( i==0 && ((j+n)-sum)==0)
    System.out.print((j+n)-sum);
else if( i!=0 && ((j+n)-sum)!=0)
    System.out.print((j+n)-sum);

    System.out.println();
    }
    }
    public static void main(String args[])throws Exception
    {
     NumberCombination ob=new NumberCombination();
     ob.take();
     }
     }


Related PostBlueJ Programs on Number



No comments:

Post a Comment

Subscribe via email

Enter your email address:

Delivered by FeedBurner