A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 陈泰延 中级黑马   /  2012-12-24 16:39  /  1784 人查看  /  7 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

  1. class FunctionDemo
  2. {
  3.         public static void main(String[] args)
  4.         {

  5.                         boolean x=compare() ;
  6.                         System.out.println("Sum="+x);
  7.                         }
  8. public static boolean compare(int a,int b)
  9.         {
  10.         if(a==b)
  11.                   return true;
  12.         //else
  13.                 return false;
  14. }
复制代码
在学习中遇到的一点小问题

7 个回复

倒序浏览
在main()里没有给compare() 定义参数
boolean x=compare(20,30) ;
回复 使用道具 举报
laughing 发表于 2012-12-24 16:54
在main()里没有给compare() 定义参数
boolean x=compare(20,30) ;

http://bbs.itheima.com/thread-31067-11-1.html
你在这里申请改名吧
回复 使用道具 举报
1.在主函数中没有给 boolean x=compare()定义参数,没办法调用compare函数
2.还有没有给输出的sum定义类型,无法输出
3."sum"作为一个变量,要全部小写
4.最后结尾少写了个“}”括号

点评

谢谢你  发表于 2012-12-24 19:12
回复 使用道具 举报
public static boolean compare(int a,int b) 你的compare方法定义的有参的函数。
而你在main()方法中调用的时候。
boolean x=compare() ;没有传参

点评

谢谢你  发表于 2012-12-24 19:12
回复 使用道具 举报
调用方法要传入参数啊
回复 使用道具 举报
laughing 发表于 2012-12-24 16:54
在main()里没有给compare() 定义参数
boolean x=compare(20,30) ;

O(∩_∩)O谢谢
回复 使用道具 举报
黄锦成 发表于 2012-12-24 17:04
调用方法要传入参数啊

O(∩_∩)O谢谢
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马