Java 按其大小对明细表进行编号
我想写一个程序,它将扫描cmd中的3个InputsNumber,并根据大小进行排序 例如,我插入10 3 8 程序应打印3 8 10 我尝试了这个程序,但cmd给了我错误 谢谢大家!Java 按其大小对明细表进行编号,java,Java,我想写一个程序,它将扫描cmd中的3个InputsNumber,并根据大小进行排序 例如,我插入10 3 8 程序应打印3 8 10 我尝试了这个程序,但cmd给了我错误 谢谢大家! import java.util.Scanner; import java.util.*; public class bySize{ public static void main(String []args){ Scanner sc = new Scanner(System.in);
import java.util.Scanner;
import java.util.*;
public class bySize{
public static void main(String []args){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
if((a<b)&&(b<c)){
System.out.println(a,b,c);
}
else if((a<c)&&(c<b)){
System.out.println(a,c,b);
}
else if((b<a)&&(a<c)){
System.out.println(b,a,c);
}
else if((b<c)&&(c<a)){
System.out.println(b,c,a);
}
else if((c<b)&&(b<a)){
System.out.println(c,b,a);
}
else if((c<a)&&(a<b)){
System.out.println(c,a,b);
}
}
}
您可以按如下方式进行操作:
import java.util.Scanner;
import java.util.*;
public class BySize {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int c = sc.nextInt();
if ((a < b) && (b < c)) {
System.out.printf("%d, %d, %d",a, b, c);
} else if ((a < c) && (c < b)) {
System.out.printf("%d, %d, %d",a, c, b);
} else if ((b < a) && (a < c)) {
System.out.printf("%d, %d, %d",b, a, c);
} else if ((b < c) && (c < a)) {
System.out.printf("%d, %d, %d",b, c, a);
} else if ((c < b) && (b < a)) {
System.out.printf("%d, %d, %d",c, b, a);
} else if ((c < a) && (a < b)) {
System.out.printf("%d, %d, %d",c, a, b);
}
}
}
问题在于System.out.println语句,当您向它传递三个参数时,它只能接受一个参数或不接受任何参数。如果仍要使用System.out.println,可以像System.out.printlna+、+b+、+c一样使用它,即将所有三个参数组合为一个参数 cmd give me errors不是一个有意义的问题陈述。请将您的问题包括您遇到的错误,以及您如何运行该程序的具体细节。使用System.out.printlna+,+b+,+c;这种款式。