In java ,after executing program do we get perfect reply

See below program ,and execute it using jdk1.6,do i get ans

Page 1 of 1

4 Replies - 850 Views - Last Post: 22 February 2008 - 09:00 AM Rate Topic: -----

#1 praveen_waves  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 21-February 08

In java ,after executing program do we get perfect reply

Posted 21 February 2008 - 09:06 PM

import java.util.Scanner;
class perfect1
{
  public static void main(String args[])
      {
         Scanner s=new Scanner(System.in);
         int n=s.nextInt();
         int esum=0;
         int osum=0; 
           if(n==1)
            {
                 System.out.println("perfect number");
                   }
         else
            {
         if(n%2==0)
           {
               for(int i=1;i<=n/2;i++)
                  {
                      if(n%i==0)
                        {
                            esum+=i;
                            }
                         }
                if(esum==n)
                   {
                      System.out.println("perfect number");
                    }
                else
                  {
                    System.out.println("not a perfect number");
                     }
          }     
            else
              { 

                 for(int i=1;i<=n/2;i++) 
                   {
                      if(n%i==0)
                        {
                           osum+=i;                    
                            }                                
                          }
                    if(osum==n)
                      {
                         System.out.println("perfect number");
                           }
                     else{
                           System.out.println("not a perfect number");
                              }
                         }   
                    }
              }
         } 
:v:
:v:
QUESTION:
SEE WHILE COMPILING WE DO IT AS JAVAC CLASSNAME.JAVA
AND THEN WE EXECUTE IT BY SAYING JAVA FILENAME..
DO WE GET REQUIRED ANSWER?
PROBLEM:FOR ME AFTER EXECUTING MEANS JAVA PERFECT I M GETTING CURSOR REMAINED BUT I M NOT GETTING ANSWER

This post has been edited by praveen_waves: 22 February 2008 - 08:59 AM


Is This A Good Question/Topic? 0
  • +

Replies To: In java ,after executing program do we get perfect reply

#2 capty99  Icon User is offline

  • i am colt mccoy
  • member icon

Reputation: 98
  • View blog
  • Posts: 10,081
  • Joined: 26-April 01

Re: In java ,after executing program do we get perfect reply

Posted 21 February 2008 - 09:12 PM

a) put your code in the correct code tags [*code][*/code] w/o the astericks

B) tell us what your question is
Was This Post Helpful? 0
  • +
  • -

#3 bhandari  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 9
  • View blog
  • Posts: 754
  • Joined: 31-January 08

Re: In java ,after executing program do we get perfect reply

Posted 22 February 2008 - 12:04 AM

Quote

do we get perfect reply


what do you mean by that??
Was This Post Helpful? 0
  • +
  • -

#4 Thenextneo  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 23
  • Joined: 04-December 07

Re: In java ,after executing program do we get perfect reply

Posted 22 February 2008 - 07:02 AM

View Postbhandari, on 22 Feb, 2008 - 12:04 AM, said:

Quote

do we get perfect reply


what do you mean by that??



A perfect number is one whos divisors are multipled together to = the number such as 6.

The multiples of 6 are 1 2 and 3. 1*2*3=6.

6 is a perfect number.


View Postpraveen_waves, on 21 Feb, 2008 - 09:06 PM, said:

import java.util.Scanner;
class perfect1
{
  public static void main(String args[])
      {
         Scanner s=new Scanner(System.in);
         int n=s.nextInt();
         int esum=0;
         int osum=0; 
           if(n==1)
            {
                 System.out.println("perfect number");
                   }
         else
            {
         if(n%2==0)
           {
               for(int i=1;i<=n/2;i++)
                  {
                      if(n%i==0)
                        {
                            esum+=i;
                            }
                         }
                if(esum==n)
                   {
                      System.out.println("perfect number");
                    }
                else
                  {
                    System.out.println("not a perfect number");
                     }
          }     
            else
              { 

                 for(int i=1;i<=n/2;i++) 
                   {
                      if(n%i==0)
                        {
                           osum+=i;                    
                            }                                
                          }
                    if(osum==n)
                      {
                         System.out.println("perfect number");
                           }
                     else{
                           System.out.println("not a perfect number");
                              }
                         }   
                    }
              }
         } 
:v:
:v:


Also other than the code tags, can you please add in what your problem is. We need to see the problem before we can help.
Was This Post Helpful? 0
  • +
  • -

#5 praveen_waves  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 21-February 08

Re: In java ,after executing program do we get perfect reply

Posted 22 February 2008 - 09:00 AM

View Postcapty99, on 21 Feb, 2008 - 09:12 PM, said:

a) put your code in the correct code tags [*code][*/code] w/o the astericks

B) tell us what your question is

SORRY SIR I HAVE GIVEN MY QUESTION ND PROBLEM PLZ SEE IT SIR
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1