java新手,看一下这个小问题

为不为 2013-10-22 04:52:25
import java.util.Scanner;
public class s{
public static void main(String [] args){
s hao=new s();
s.max();

}
int void max(int a,int b, int c, int t){
Scanner q=new Scanner(System.in);
System.out.print("请输入您的数字");
a=q.nextInt();
b=q.nextInt();
c=q.nextInt();
if(a<b){
t=a;a=b;b=t;
}
if(a<c){
t=a;a=c;c=t;
}
if(b<c){
t=b;b=c;c=t;
}
System.out.println("最大数字依次是:"+a+"/t"+b+"/t"+c);
}
这个哪里有问题啊,

现在自学java
现在都不知道从哪里学好了,
java 常见类库怎么学啊?
流程控制不知道怎么搞?
迷茫ing
...全文
422 12 打赏 收藏 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
sunflower93 2014-03-10
  • 打赏
  • 举报
回复
这样啊,学习到了
sp007024 2013-10-22
  • 打赏
  • 举报
回复
引用 10 楼 sunflower93 的回复:
话说用Scanner in = new Scanner(System.in); int a = in.nextInt(); 可以读入其他类型的数据吗?
可以 你输入在控制台的对象 都可以读入
sunflower93 2013-10-22
  • 打赏
  • 举报
回复
话说用Scanner in = new Scanner(System.in); int a = in.nextInt(); 可以读入其他类型的数据吗?
yaowangt 2013-10-22
  • 打赏
  • 举报
回复
s.max() 调用的是 max()方法,你根本就没有这个方法,你有的是max(int a,int b,int c,int t)方法,而且你的t作为一个中转的 属性,完全可以在方法里边定义 int t=0;不需要方法传进去
寻找IT之路 2013-10-22
  • 打赏
  • 举报
回复
s.max()与int void max(int a,int b, int c, int t)不匹配,还有去掉int ,max(int a,int b,int c)
wolfguy_pan 2013-10-22
  • 打赏
  • 举报
回复
引用 6 楼 u011747152 的回复:
Scanner in = new Scanner(System.in); System.out.println("Enter three number,please"); int a = in.nextInt(); int b = in.nextInt(); int c = in.nextInt(); 为什么这个不可以放在max方法下面
输入输出口放在main函数中。 这里涉及到多线程以及JVM编译的结束标志问题不多解释了。 你想放在max中也可以,在5楼代码中,12行改为:max(); 16行括号内函数变量删掉 8,9,10行代码放在int t=0;下面
为不为 2013-10-22
  • 打赏
  • 举报
回复
Scanner in = new Scanner(System.in); System.out.println("Enter three number,please"); int a = in.nextInt(); int b = in.nextInt(); int c = in.nextInt(); 为什么这个不可以放在max方法下面
wolfguy_pan 2013-10-22
  • 打赏
  • 举报
回复
简单的修改了一下,你对比一下。
import java.util.Scanner;

public class s {
			public static void main(String [] args){
				Scanner in  = new Scanner(System.in);
				
				System.out.println("Enter three number,please");
				int a = in.nextInt();
				int b = in.nextInt();
				int c = in.nextInt();
				
				max(a,b,c);
				in.close();
			}
			/*----max method part----*/
			static void max(int a,int b,int c){
					int t = 0;
					if(a<b){
						t=a;a=b;b=t;
						}
						if(a<c){
						t=a;a=c;c=t;
						}
						if(b<c){
						t=b;b=c;c=t;
						}
						System.out.println("Sorted Order : "+a+" "+b+" "+c);
			}
}
Enter three number,please
3 4 5
Sorted Order : 5 4 3
还有一个错误就是你调用max没有传参。
为不为 2013-10-22
  • 打赏
  • 举报
回复
改了两个错误,可还是不行啊
tjj_fisher 2013-10-22
  • 打赏
  • 举报
回复
Java函数定义: 返回值类型 函数名(形参列表)
int void max(int a,int b, int c, int t)
这一句中有两中返回类型啦大哥,按你程序的意思函数体本意是直接输出最大值,所以去掉void就OK啦 推荐你看《JAVA2核心技术第1卷.基础知识7th.pdf》
wolfguy_pan 2013-10-22
  • 打赏
  • 举报
回复
接楼上, s hao=new s(); s.max(); 1.s从规范来讲,最好大写 2.max不是static函数,不可以这么写,改为hao.max 另外,max方法中,int t最好声明在method内,不要声明在argument中。(还有就是楼上说的返回类型,只能一个) 最后,打开的scanner没有关闭,用q.close()关闭。 我把你的代码改改发上来吧
末日哥 2013-10-22
  • 打赏
  • 举报
回复
int void max(int a,int b, int c, int t){
2种返回类型。。你想干嘛。。。

62,620

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧