| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1177 人关注过本帖
标题:java输出最大数
只看楼主 加入收藏
wxzyn123
Rank: 1
来 自:江苏
等 级:新手上路
帖 子:50
专家分:0
注 册:2007-9-15
收藏
 问题点数:0 回复次数:11 
java输出最大数

import java.io.*;
public class MyMath
{
//static int a,b,c;
public static void Max(int a,int b,int c)
{
if(a>b)
{
if(a>c) System.out.println("the bigest number is "+a);
else System.out.println("the bigest number is "+c);
}
else
{
if(b>c) System.out.println("the bigest number is "+b);
else System.out.println("the bigest number is "+c);

}
}
public static void main(String[] args)throws IOException
{
MyMath m=new MyMath();
int n1;
int n2;
int n3;
System.out.println("please enter the first number:");
n1=(int)System.in.read();
System.out.println("please enter the second number:");
n2=(int)System.in.read();
System.out.println("please enter the third number:");
n3=(int)System.in.read();
m.Max(n1,n2,n3);
}
}

就是这个,就是要求输入三个数,然后输出最大数

运行时只输入一个数就结束程序了,不知道问题出在哪


搜索更多相关主题的帖子: java 大数 int number 
2007-10-17 19:18
werth
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2007-10-17
收藏
得分:0 
回复:(wxzyn123)java输出最大数
灌水的
2007-10-17 19:31
aaron453
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2007-8-20
收藏
得分:0 

2007-10-17 20:19
zzhang0821
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2007-10-17
收藏
得分:0 
铺路的
不明白 看不懂你的代码!
2007-10-17 20:30
zmzlx
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2007-10-16
收藏
得分:0 

import java.io.*;
public class MyMath
{
//static int a,b,c;
public static void Max(int a,int b,int c)
{
if(a>b)
{
if(a>c) System.out.println("the bigest number is "+a);
else System.out.println("the bigest number is "+c);
}
else
{
if(b>c) System.out.println("the bigest number is "+b);
else System.out.println("the bigest number is "+c);

}
}
public static void main(String[] args)throws IOException
{
MyMath m=new MyMath();/*请问你定义的类中有这个构造函数吗?*/
int n1;
int n2;
int n3;
System.out.println("please enter the first number:");
n1=(int)System.in.read();
System.out.println("please enter the second number:");
n2=(int)System.in.read();
System.out.println("please enter the third number:");
n3=(int)System.in.read();
m.Max(n1,n2,n3);
}
}
还有你的Max(int a,int b,int c)方法是比较烦琐的,象这类比较小规模问题,用递归思想是比较简单的.

2007-10-18 08:38
凡喻
Rank: 1
等 级:新手上路
帖 子:17
专家分:0
注 册:2007-10-17
收藏
得分:0 
进来学习学习  呵呵

2007-10-18 09:04
baby66
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2007-10-16
收藏
得分:0 

import java.io.*;
public class MyMath
{
//static int a,b,c;
public static void Max(int a,int b,int c)
{
if(a>b)
{
if(a>c) System.out.println("the bigest number is "+a);
else System.out.println("the bigest number is "+c);
}
else
{
if(b>c) System.out.println("the bigest number is "+b);
else System.out.println("the bigest number is "+c);

}
}
public static void main(String[] args)throws IOException
{
MyMath m=new MyMath();/*请问你定义的类中有这个构造函数吗?*/
int n1;
int n2;
int n3;
BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));

System.out.println("please enter the first number:");
//n1=(int)System.in.read();
n1=Integer.parseInt(bf.readLine());
System.out.println("please enter the second number:");
//n2=(int)System.in.read();
n2=Integer.parseInt(bf.readLine());
System.out.println("please enter the third number:");
//n3=(int)System.in.read();
n3=Integer.parseInt(bf.readLine());
m.Max(n1,n2,n3);
}
}

是因为(int)System.in.read();这句话只能作为一个输入源进行输入
所以帮你换了个输入流:BufferedReader InputStreamReader
System.in这个代表从键盘输入
然后在数字的处理上用到了包装类的思想,先把你从键盘中输入的数转化成字符串bf.readLine()然后用Integer.parseInt(bf.readLine());
转化成int数值就可以了

2007-10-18 09:33
liwanlei
Rank: 1
等 级:新手上路
帖 子:18
专家分:0
注 册:2006-9-12
收藏
得分:0 
伟大的

2007-10-18 10:18
wxzyn123
Rank: 1
来 自:江苏
等 级:新手上路
帖 子:50
专家分:0
注 册:2007-9-15
收藏
得分:0 
谢谢你们
2007-10-18 16:19
beiny
Rank: 1
等 级:新手上路
帖 子:14
专家分:0
注 册:2007-10-18
收藏
得分:0 

学习JAVA中

2007-10-19 03:18
快速回复:java输出最大数
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012140 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved