Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2012
    Posts
    30
    Rep Power
    0

    Default Finding bug and correcting it

    print the larger number first
    there is one bug


    public void bug(int a, int b)
    {

    int first = a ;
    int second = b;
    int temp = 0;
    if (a>b)
    {
    temp = a;
    first = b;
    second = a;
    }
    System.err.println(first + "" + second) ;

    }

    How would I be able to test this in netbeans?

  2. #2
    Darkzombies is offline Senior Member
    Join Date
    Nov 2012
    Posts
    105
    Rep Power
    0

    Default Re: Finding bug and correcting it

    Press the compile button?

  3. #3
    Join Date
    Oct 2012
    Posts
    30
    Rep Power
    0

    Default Re: Finding bug and correcting it

    I can't run it. My professor just gave me that piece of code and said to find the bug. If I can run it I'll be able to figure it maybe but I don't know how to make the class so i can run it. I have something like this
    Java Code:
    public class bug {
    
        public static void main(String[] args) {
           public void bug(int a, int b)
    {
    
    int first = a ;
    int second = b;
    int temp = 0;
    if (a>b)
    {
    temp = a;
    first = b;
    second = a; 
    }
    System.err.println(first + "" + second) ; 
    
    }
        }
    But it says illegal start of expression on the line where public void bug(int a, int b) is located.
    What is actually meant by print the larger number first?

  4. #4
    Darkzombies is offline Senior Member
    Join Date
    Nov 2012
    Posts
    105
    Rep Power
    0

    Default Re: Finding bug and correcting it

    Methods can't be inside other methods.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,036
    Rep Power
    20

    Default Re: Finding bug and correcting it

    You don't need to run it.
    Step through it with a piece of paper.
    Assume it is called with a=4 and b=3.
    See what result you end up with.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Having trouble correcting this code.
    By Denis2k11 in forum New To Java
    Replies: 7
    Last Post: 10-14-2012, 01:13 AM
  2. Finding the Median
    By system5634 in forum New To Java
    Replies: 1
    Last Post: 02-07-2012, 01:30 PM
  3. finding max value
    By rocky86 in forum New To Java
    Replies: 6
    Last Post: 10-10-2010, 01:37 AM
  4. Replies: 3
    Last Post: 02-22-2010, 04:20 AM
  5. Finding where to draw
    By flok in forum AWT / Swing
    Replies: 4
    Last Post: 11-24-2009, 05:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •