Ask Experts Questions for FREE Help !
Ask
    oneoderja's Avatar
    oneoderja Posts: 2, Reputation: 1
    New Member
     
    #1

    Sep 30, 2012, 07:25 PM
    Need help into passing the object into the method and make it work
    Define a class called ‘twoInt’ with two public integer fields a and b
    In the constructor of ‘twoInt’, initialize the a and b to be 1 and 2
    Create an instance ‘mytwoInt’ in the main method
    Write a method ‘swap’ (not the method of the class ‘twoInt’) and pass the above instance ‘mytwoInt’ into the method, swap two a and b in the method
    Print out a and b in the main method
    System.out.print(object.a + ‘ ‘ + object.b);
    Swap(object);
    System.out.print(object.a + ‘ ‘ + object.b);

    My Code:

    public class TwoInt
    {
    public static void main (String [] args)
    {
    int a;
    int b;

    TwoInt myTwoInt = new TwoInt();

    System.out.println(myTwoInt.a + " " + myTwoInt.b);

    }

    public TwoInt()
    {
    a = 1;
    b = 2;
    }

    public void swap (myTwoInt int a, int b)
    {
    int tmp = a;

    a = b;
    b = tmp;

    System.out.println(myTwoInt.a + " " + myTwoInt.b);

    }

Check out some similar questions!

Calculate the work done accelerating a 2.0 kg object from 2.0 m/s to 3.0 m/s in 2.0s. [ 3 Answers ]

I don't understand how to calculate this question, it would be great if anyone could help

Make a group Policy object for a login script [ 0 Answers ]

Hi my names Tom, And I'm trying to figure out a way to map everyone in my offices personal share folder to their computer when they logon. I have over 26 employees. I'd like to create a new group policy that does this but never done before. Would I put all the users on the same login script? How...

Careers that produce or work with a tangible object [ 2 Answers ]

I want to know about careers that call on someone to deal with quickly changing situations and problem solving but that also produces a tangible object or deals with a tangible thing.

Finding matrix transpose - why doesn't it work when passing pointer argument? [ 6 Answers ]

Hi I'm adapting some code I've written using 2d arrays (to represent matrices) to handle large arrays such that double matrix goes to double **matrix and then I'm using malloc. It seems to work fine for part of my program up to where I have to find the matrix transpose at which point it does...


View more questions Search
 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.