class Change1 {
  int a,b;
 Change1(int a,int b){
  this.a = a;
  this.b = b;
 } void set(int a,int b){
     int c = a;
     a = b;
     b = c;
     
} void show(int a,int b) {
       
   System.out.println(a);
   System.out.println(b);
               
 }
}
public class Change{
 public static void main(String []args) {
        Change1 d = new Change1(1,2);
        d.set();
        d.show();
 }
}它说我的d.set和d.show不能被调用。
帮我看下哪里出错了,小弟无能。- -一新手。

解决方案 »

  1.   

    d.set(1,3);
      d.show(2,4);
      

  2.   

    public static void main(String []args) {public static void main(String[] args) {
      

  3.   

    你的set和show都是两参的,你调的是无参的,你说能调不
      

  4.   

    1.你可以像楼上那种方式调用.
    2.你也可以把void set(int a,int b)和void show(int a,int b)都改成
    void set()和void show().
      

  5.   

    void set(int a,int b)这里是有两个参数 a b
    void show(int a,int b)这里是有两个参数 a b而你的
     d.set(); 这里没有给他参数
     d.show();
    因为你没有写他的无参方法 你写的是两个形参的方法 所以你调用的时候得给他传参
    d.set(1,2);
    d.show(2,1);
    /*或则你也可以这样写 
    先定义一个成员变量 */
    int a , b ;
     void set(){
      int c = a;
      a = b;
      b = c;
        
    } void show() {
        
      System.out.println(a);
      System.out.println(b);
        
     }
      

  6.   

    根据楼主写的,我自己的理解是,楼主想调用构造函数中传进来的 俩个参数进行交换值,既然,你构造函数中已经对ab进行了赋值,那么void set(int a,int b)里面是没必要要的,而且你引用的时候是通过void set()来引用的,这参数不搭配,肯定会错呀,你直接用set()不是更好吗 ?
      

  7.   


    void set();
    void show();
    或者
    d.set(1,2);
    d.show(2,1);
      

  8.   

    楼主,至少你要好好看下ide的报错信息吧,它应该明确的说明了不对在什么地方。
    有参的函数,无参去调,显然错 的。Description Resource Path Location Type
    The method get1(String, String, String) in the type Test1 is not applicable for the arguments ()
      

  9.   

    你的set(),show(),方法都是带参数的,但是你调用的时候却没有传进参数来,这样是不行的!你或者把方法中的参数列表去掉,或者在调用方法的时候传进参数,但是set(),show(),chang1()的参数相同,否则达不到你想要交换参数值的效果!
      

  10.   

    没有mian函数 还没有参数