java怎样设置用户输入的数值?
{intx,y,z,t;scanf("%d",&z);scanf("%d",&y);scanf("%d",&x);}类似c++中的上面一个作用,在Java中怎样实现?#i...
{int x,y,z,t;
scanf("%d",&z);
scanf("%d",&y);
scanf("%d",&x);}
类似c++中的上面一个作用,在Java中怎样实现?
#include<stdio.h>
main()
{int x,y,z,t;
printf("请输入三个数字:\n");
scanf("%d",&z);
scanf("%d",&y);
scanf("%d",&x);
if(x<y)
{t=x,x=y,y=t;}
if(x<z)
{t=x,x=z,z=t;}
if(y<z)
{t=y,y=z,z=t;}
printf("从大到小:");
printf("%d,%d,%d",x,y,z);
}用java怎样编写? 展开
scanf("%d",&z);
scanf("%d",&y);
scanf("%d",&x);}
类似c++中的上面一个作用,在Java中怎样实现?
#include<stdio.h>
main()
{int x,y,z,t;
printf("请输入三个数字:\n");
scanf("%d",&z);
scanf("%d",&y);
scanf("%d",&x);
if(x<y)
{t=x,x=y,y=t;}
if(x<z)
{t=x,x=z,z=t;}
if(y<z)
{t=y,y=z,z=t;}
printf("从大到小:");
printf("%d,%d,%d",x,y,z);
}用java怎样编写? 展开
2个回答
展开全部
现在一般都用
java.util.Scanner
原始一点的用
java.io.InputStream
Scanner使用比较简单 InputStream使用还有捕获异常
class a
{
public static void main(String [] args)
{
int x,y,z,t=0;
System.out.println("请输入三个数字:\n");
java.util.Scanner sc =new java.util.Scanner(System.in);
x = sc.nextInt();
y = sc.nextInt();
z = sc.nextInt();
if(x<y)
{t=x;x=y;y=t;}
if(x<z)
{t=x;x=z;z=t;}
if(y<z)
{t=y;y=z;z=t;}
System.out.println("从大到小:");
System.out.println(x + " " + y + " " + z);
}
}
java.util.Scanner
原始一点的用
java.io.InputStream
Scanner使用比较简单 InputStream使用还有捕获异常
class a
{
public static void main(String [] args)
{
int x,y,z,t=0;
System.out.println("请输入三个数字:\n");
java.util.Scanner sc =new java.util.Scanner(System.in);
x = sc.nextInt();
y = sc.nextInt();
z = sc.nextInt();
if(x<y)
{t=x;x=y;y=t;}
if(x<z)
{t=x;x=z;z=t;}
if(y<z)
{t=y;y=z;z=t;}
System.out.println("从大到小:");
System.out.println(x + " " + y + " " + z);
}
}
追问
不太清楚具体用法,能举个列子让我参考么,谢谢!
追答
class a
{
public static void main(String [] args)
{
int x,y,z,t=0;
System.out.println("请输入三个数字:\n");
java.util.Scanner sc =new java.util.Scanner(System.in);
x = sc.nextInt();
y = sc.nextInt();
z = sc.nextInt();
if(x<y)
{t=x;x=y;y=t;}
if(x<z)
{t=x;x=z;z=t;}
if(y<z)
{t=y;y=z;z=t;}
System.out.println("从大到小:");
System.out.println(x + " " + y + " " + z);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询