Syvum Home Page

Home > Discussions > For all activities

Discussion topic: Contributed Answer/Explanation to Q. 3

Viewing replies        View entire discussion

To go to the homepage of this topic, click here.
Home: asha_g_mcaOriginal MessageReply  
Subject: Contributed Answer/Explanation to Q. 1
   JAVA
   
   class lucky
   
   
    {
   
   
    int arr[ ];
   
   
   public static void display(int q, int n)
   
   
   {int size=n/q;
   
   
     int b[ ]= new int[size];
   
   
   for(int i=0,j=0;j<arr.length;i++,j+=q) b[i]=arr[ j ];
   
   
    System.out.println("Removing every" +q +"number we
   get:");
   
   
    for(int i=0;i<=b.length;i+=q)  System.out.print(b[i]+"   
   ");
   
   
   System.out.println();
   
   
   }
   
   
   public static void main(int n)
   
   
   {
   
   
   if (n<50)
   
   
   {
   
   
    int q=1; 
   
   
   for(int i=1;i<=n;i++) arr[i]=i;
   
   
   boolean flag=true;
   
   
   while(flag)
   
   
   {
   
   
   display(q,n);
   
   
   q++;
   
   
   if (q>n ) {
   
   
          flag=false;
   
   
          break;
   
   
               }
   
   
   }
   
   
   }
   
   
   else
   
   
   System.out.println("Enter a number less than 50");
   
   
   }
   
   
   }
   
   
    

Posted at: Tue Sep 14 06:56:34 2010 (GMT)

Page 1 of 1
From: asha_g_mcaReply 1 of 1Reply
Subject: Contributed Answer/Explanation to Q. 1
   JAVA
   
   class lucky 
   
   
    { 
   
   
    int arr[ ]; 
   
   
   public static void display(int q, int n) 
   
   
   {int size=n/q; 
   
   
     int b[ ]= new int[size]; 
   
   
   for(int i=0,j=0;j 
   
   
    System.out.println("Removing every" +q +"number we
   get:"); 
   
   
    for(int i=0;i<=b.length;i+=q)  System.out.print(b[i]+"   
   "); 
   
   
   System.out.println(); 
   
   
   } 
   
   
   public static void main(int n) 
   
   
   { 
   
   
   if (n<50) 
   
   
   { 
   
   
    int q=1; 
   
   
   for(int i=0;i<n;i++) arr[i]=i+1; 
   
   
   boolean flag=true; 
   
   
   while(flag) 
   
   
   { 
   
   
   display(q,n); 
   
   
   q++; 
   
   
   if (q>n ) { 
   
   
          flag=false; 
   
   
          break; 
   
   
               } 
   
   
   } 
   
   
   } 
   
   
   else 
   
   
   System.out.println("Enter a number less than 50"); 
   
   
   } 
   
   
   } 
   
   
    

Posted at: Tue Sep 14 06:57:57 2010 (GMT)

Page 1 of 1

To post to this forum, you must be signed in as a Syvum member. Please sign in / register as a member.

Contact Info © 1999-2024 Syvum Technologies Inc. Privacy Policy Disclaimer and Copyright