You can use any primitive type you want. test( something ) will give
error if the method does not have the right type. You should get a
light bulb and it will ask you to create the appropriate method. Then
just change the parameter inside the newly generated method and do
your println(); stuff.. I think everyone else has answered your error
question. Play around with different types.
One type one method or pass in more than one. Just remember you need
to keep track of how many you pass in as you have discovered.

On Aug 8, 11:22 am, "tinyang" <[email protected]> wrote:
> Hello
>
> I am trying to complete 3.1 of Lab 1011.  Below is 3.1:
>
> 4. (For your own exercise) Modify TestPassByValue.java as following.  Build
> and run the project.
>
> *       Pass the second primitive type parameter to the test(..) method -
> you can choose any primitive type parameter (such as long or boolean).
> *       Set the value of the second parameter before calling the test(..)
> method.  And change the value of the passed parameter within the test(..)
> method as you did with the first parameter in Code-3.11 above.
> *       Modify the System.out.println(..) methods in the Code-3.11 above to
> display the values of both the first parameter and second parameter.
>
> Here is my code:
>
> public class TestPassByValue {
>
>     /**
>      * @param args the command line arguments
>      */
>     public static void main(String[] args) {
>         // TODO code application logic here
>         int i = 10;
>         long k = 500;
>
>         // Print the value of i
>         System.out.println("start of the main method and i = " + i);
>         System.out.println("start of the main method and k = " + k);
>
>         // Call method test, which is defined below
>         // and pass int value as a parameter.  Since
>         // int is a primitive type, this parameter is passed
>         // by value.
>         test( i );
>         test( k );
>
>         // print the value of i. please note that  i not changed
>         System.out.println("end of the main method and i = " + i);
>         System.out.println("end of the main method and k = " + k);
>     }
>
>     // Another static method in the TestPassByValue class
>     public static void test(int j, long m){
>
>         System.out.println("start of the test method and j = " + j);
>         System.out.println("start of the test method and m = " + m);
>
>         // change value of parameter i
>         j = 33;
>         m = 501;
>
>         System.out.println("end of the test method and j = " + j);
>         System.out.println("end of the test method and m = " + m);
>     }
>
> }
>
> It indicates errors for the following lines
> test( i );
> required Int, long
> found: int
>
> test( k );
> required Int, long
> found: int
>
> Shouldn't it be able to accept either int or long?  Thanks for any help.
>
> --
> :-)
> P Please don't print this e-mail unless you really need to.

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to