Topic: java 白痴,求救!这个编程怎么做啊!(实现两个参数的相加)

  Print this page

1.java 白痴,求救!这个编程怎么做啊!(实现两个参数的相加) Copy to clipboard
Posted by: 232123484
Posted on: 2005-11-20 22:06

我们老师给了我这道题,可是我想了几天都不知那个方法体怎么写!请高手们给我解答啊!
题目如下:
定义一个方法,方法名为qiuhe,参数为两个整型变量,返回值为整型,修饰符为static;这个方法能实现两个参数的相加,并能返回和。然后在main方法中调用qiuhe()方法,求3加5的和。(main方法是一个静态方法,它只能直接访问类中的其它静态方法,如果qiuhe方法是一个非静态方法,那么main方法就不能直接访问了,必须创建对象才能访问)

2.Re:java 白痴,求救!这个编程怎么做啊! [Re: 232123484] Copy to clipboard
Posted by: anatoranato
Posted on: 2005-11-20 22:26

不是很清楚你到底想做什么,做这个?
public class Test{
public static void main(String [] args){
int result = qiuhe(3, 5);
}

static int qiuhe(int a, int b){
return a+b;
}
}

3.Re:java 白痴,求救!这个编程怎么做啊! [Re: 232123484] Copy to clipboard
Posted by: lecone
Posted on: 2005-12-30 16:00

这个程序感觉还有点错..
public class ntest {
static int qiuhe(int a,int b){
  return a+b;
  
}
  public static void main(String[] args) {
     int r =qiuhe(3,5);
      }
}
是不是这样好点.

4.Re:java 白痴,求救!这个编程怎么做啊! [Re: lecone] Copy to clipboard
Posted by: why
Posted on: 2005-12-30 19:06

lecone wrote:
这个程序感觉还有点错..
public class ntest {
static int qiuhe(int a,int b){
return a+b;

}
public static void main(String[] args) {
int r =qiuhe(3,5);
}
}
是不是这样好点.

QuestionWhat's the difference?
public class ntest // bad class name!

5.Re:java 白痴,求救!这个编程怎么做啊!(实现两个参数的相加) [Re: 232123484] Copy to clipboard
Posted by: xtb_0129
Posted on: 2005-12-31 09:16

class TestDemo
{static int qiuhe(){
Scanner sc=new Scanner(new InputStreamReader(System.in));
int a=sc.nextInt();
int b=sc.nextInt();
return a+b;
}
public static void main(String [] args)
{
int r=qiuhe();
Sytem.out.println(r);
}

6.Re:java 白痴,求救!这个编程怎么做啊!(实现两个参数的相加) [Re: 232123484] Copy to clipboard
Posted by: guowei1982
Posted on: 2005-12-31 17:17

一个 比 一个经典!!

7.Re:java 白痴,求救!这个编程怎么做啊!(实现两个参数的相加) [Re: 232123484] Copy to clipboard
Posted by: solo
Posted on: 2006-01-01 18:15

都不错呀
不过还是元老搞笑呀

8.Re:java 白痴,求救!这个编程怎么做啊!(实现两个参数的相加) [Re: 232123484] Copy to clipboard
Posted by: freewindy
Posted on: 2006-03-11 19:39

简单点吧,anatoranato
的答案就可以了..

9.Re:java 白痴,求救!这个编程怎么做啊!(实现两个参数的相加) [Re: 232123484] Copy to clipboard
Posted by: 天涯一线
Posted on: 2006-03-15 23:41

class Test{
Test(){
int x,y;
}
void qiuhe(int x,int y){
int r;
r=x+y;
System.out.println("求和结果是:"+r);
}
}
public class JiSuan{
public static void main(String[] args){
Test result=new Test();
result.qiuhe(3,5);
}
}

10.Re:java 白痴,求救!这个编程怎么做啊!(实现两个参数的相加) [Re: 232123484] Copy to clipboard
Posted by: BeanBean
Posted on: 2006-03-17 21:49

小问题能见到大学问~~

11.Re:java 白痴,求救!这个编程怎么做啊!(实现两个参数的相加) [Re: 232123484] Copy to clipboard
Posted by: 学长
Posted on: 2006-03-18 22:33

学习ing,顶

12.Re:java 白痴,求救!这个编程怎么做啊!(实现两个参数的相加) [Re: 232123484] Copy to clipboard
Posted by: wsk700c
Posted on: 2006-05-29 21:18

小问题能见到大学问---------同意!!!!!

13.Re:java 白痴,求救!这个编程怎么做啊!(实现两个参数的相加) [Re: 232123484] Copy to clipboard
Posted by: hzx002
Posted on: 2006-05-29 22:55

public class Text{
    public int qiuhe(int i, int j){
      return i + j;
    }
    
    public static void main(String[] args) {
        Text text = new Text();
        int result = text.qiuhe(3,5);
        System.out.println(result);
    }
}

14.Re:java 白痴,求救!这个编程怎么做啊!(实现两个参数的相加) [Re: 232123484] Copy to clipboard
Posted by: zqswork
Posted on: 2006-05-30 23:03

我发现我越来越爱上这里的人们了```

15.Re:java 白痴,求救!这个编程怎么做啊!(实现两个参数的相加) [Re: 232123484] Copy to clipboard
Posted by: lxh1962
Posted on: 2006-06-10 18:52

是啊,这样的讨论有助于初学者(尤其是我这样的)

16.Re:java 白痴,求救!这个编程怎么做啊!(实现两个参数的相加) [Re: 232123484] Copy to clipboard
Posted by: 灰色秋天
Posted on: 2006-06-12 18:33

xtb_0129 的程序掉了一个


}

要引起注意呀!

17.Re:java 白痴,求救!这个编程怎么做啊!(实现两个参数的相加) [Re: 232123484] Copy to clipboard
Posted by: 灰色秋天
Posted on: 2006-06-12 18:50

xtb_0129
的程序编译不成功,里面有很多错误,虽都是些很小的错误,但请各位贴手,在发程序在坛子上时,尽量避免!
以免误导像我这样的菜鸟呀!

18.Re:java 白痴,求救!这个编程怎么做啊!(实现两个参数的相加) [Re: xtb_0129] Copy to clipboard
Posted by: cxs718
Posted on: 2006-06-12 22:02

xtb_0129 wrote:
class TestDemo
{static int qiuhe(){
Scanner sc=new Scanner(new InputStreamReader(System.in));
int a=sc.nextInt();
int b=sc.nextInt();
return a+b;
}
public static void main(String [] args)
{
int r=qiuhe();
Sytem.out.println(r);
}

不能运行,是不是要把包(命名空间)也写上?

19.Re:java 白痴,求救!这个编程怎么做啊!(实现两个参数的相加) [Re: 232123484] Copy to clipboard
Posted by: 123428316
Posted on: 2006-08-30 23:05

import java.util.*;
import java.lang.*;
import java.io.*;

class args
{static int qiuhe(){
Scanner sc=new Scanner(new InputStreamReader(System.in));
int a=sc.nextInt();
int b=sc.nextInt();
return a+b;
}

public static void main(String [] args)
{
int r=qiuhe();
System.out.println(r);
}
}

20.Re:java 白痴,求救!这个编程怎么做啊!(实现两个参数的相加) [Re: 232123484] Copy to clipboard
Posted by: awrong
Posted on: 2006-08-30 23:48

这个总是要想几天???搞笑!!

21.Re:java 白痴,求救!这个编程怎么做啊!(实现两个参数的相加) [Re: 232123484] Copy to clipboard
Posted by: qingsure
Posted on: 2006-08-31 18:25

class test{
  
  public static int qiuhe(int a,int b)
  {
    return a+b;
  }

  public static void main(String[] args)
  {
    int aa = qiuhe(3,5);
    System.out.println(aa);
  }  
}

22.Re:java 白痴,求救!这个编程怎么做啊!(实现两个参数的相加) [Re: 232123484] Copy to clipboard
Posted by: lijiye
Posted on: 2006-09-04 12:35

可以使用JDK1.5里面新特性——静态引入来做,代码如下:
import static jdk5.Qiuhe1.qiuhe;

public class QiuheTest2 {
  public static void main(String[] args){
    int result;
    
    result=qiuhe(3,5);
    
    System.out.println("Result="+result);
  }
}

class Qiuhe1{
  public static int qiuhe(int a,int b){
    return a + b;
  }
}


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923