用java 从键盘输入3个整数,分别赋给整数变量a b c 然后将输入的整数按照从小到大的顺序放在变量abc中,并

用java
从键盘输入3个整数,分别赋给整数变量a b c 然后将输入的整数按照从小到大的顺序放在变量a b c中,并输三个变量的值。(各种情况都要算啊)最好源代码粘贴,复制到Eclipse
就可以用
要输入啊!!a=b呢 b=c呢或c=a呢还有a=b=c

2L你好夸张!
把下面代码放到main()方法中
Scanner s=new Scanner(System.in);
System.out.println("请输入a的值:");
int a=s.nextInt();
System.out.println("请输入b的值:");
int b=s.nextInt();
System.out.println("请输入c的值:");
int c=s.nextInt();
int x=0;
if(a>b)
{
x=a;
a=b;
b=x;
}
if(a>c)
{
x=a;
a=c;
c=x;
}
if(b>c)
{
x=b;
b=c;
c=x;
}
System.out.println(a+","+b+","+c);
温馨提示:内容为网友见解,仅供参考
第1个回答  2011-04-17
package com.zhidao.test;

public class OrderNum {

public void orderValue(int x, int y, int z) {
int a;
int b;
int c;
if (x > y && x > z) {
c = x;
if (y > z) {
a = z;
b = y;
} else {
a = y;
b = z;
}
} else if (x < y && x < z) {
a = x;
if (y > z) {
b = z;
c = y;
} else {
b = y;
c = z;
}
} else {
b = x;
if (y > z) {
a = z;
c = y;
} else {
a = y;
c = z;
}
}
System.out.println("a = "+a+"; b = "+b+"; c = "+c);
}

public static void main(String[] args)
{
OrderNum on=new OrderNum();
on.orderValue(1, 2, 3);
on.orderValue(3, 2, 1);
on.orderValue(1, 3, 2);
on.orderValue(2, 3, 1);
on.orderValue(2, 1, 3);
on.orderValue(3, 1, 2);
}
}
第2个回答  2011-04-17
public class Test {
public static void main(String args[]){
int a,b,c;
a=Integer.parseInt(args[0]);
b=Integer.parseInt(args[1]);
c=Integer.parseInt(args[2]);

int []result=new int[3];
if(a>=b){
if(a>=c){
result[0]=a;
if(b>=c){
result[1]=b;
result[2]=c;
}else{
result[1]=c;
result[2]=b;
}
}else{
result[0]=c;
result[1]=a;
result[2]=b;
}
}else {
if(c>=b){
result[0]=c;
result[1]=b;
result[2]=a;
}else{
result[0]=b;
if(a>=c){
result[1]=a;
result[2]=c;
}else{
result[1]=c;
result[2]=a;
}
}
}

a=result[2];
b=result[1];
c=result[0];

System.out.println(a);
System.out.println(b);
System.out.println(c);
}
}
第3个回答  2011-04-17
从键盘输入3个整数,分别赋给整数变量a b c 然后将输入的整数按照从小到大的顺序放在变量a b c中,并输三个变量的值。(各种情况都要算啊)最好源代码粘贴,复制到Eclipse
第4个回答  2011-04-18
public static void sortInt(int a, int b, int c)
{
int temp = 0;
if (a > b)
{
temp = b;
b = a;
a = temp;
}
if (b > c)
{
temp = c;
c = b;
b = temp;
}
if (a > b)
{
temp = b;
b = a;
a = temp;
}
System.out.println(a + "-" + b + "-" + c);
}
相似回答