本人编写的这样一个方法的程序是用方法的调用但是没有成功错误在init()!本人才用到方法不太熟悉
请各为大哥指点如何才能写好方法!有没有固定的格式!谢谢!
package untitled3;
import java.io.*;
public class number{
  /**
   * init
   */
  public void init() {
 double y=0;
int x=0;
    y=x+0.5;
 System.out.println("得数为:"+y);
  }
public static void main(String arg[]){
  int x=0;
  String s=" ";
  try{
    BufferedReader in = new  BufferedReader(new InputStreamReader(System.in));
    System.out.print("请输入一个数:");
    s=in.readLine();
    x=Integer.parseInt(s);
  }catch(IOException e){}
  init();
   }
}

解决方案 »

  1.   

    init();前面改成:
    number o = new number();
    o.init();
      

  2.   

    import java.io.*;public class number {
        public void init(int x) {
            double y = 0;
            y = x + 0.5;
            System.out.println("得数为:" + y);
        }    public static void main(String arg[]) {
            int x = 0;
            String s = " ";
            try {
                BufferedReader in = new BufferedReader(new InputStreamReader(
                        System.in));
                System.out.print("请输入一个数:");
                s = in.readLine();
                x = Integer.parseInt(s);
            } catch (IOException e) {
            }
    number num=new number();
    num.init(x);
        }
    }
      

  3.   

    double y=0;
    int x=0;
    y=x+0.5;
    int和double 相加,返回结果应该也是int吧?
      

  4.   

    int和double相加返回的结果是double型的