用java 从键盘输入3个整数,分别赋给整数变量a b c 然后将输入的整数按照从小到大的顺序放在变量abc中,并
作者&投稿:攸利 (若有异议请与网页底部的电邮联系)
int a = 3, b = 4, c = 5;
int[] array = new int[]{a, b, c};
java.util.Arrays.sort(array); //数组排序
a = array[0];
b = array[1];
c = array[2];
import java.util.Scanner;
public class TestForQ {
public static void main(String[] args){
int a = 0;
int b = 0;
int c = 0;
Scanner sc = new Scanner(System.in);
a = sc.nextInt();
b = sc.nextInt();
c = sc.nextInt();
if (a > b) {
int temp = a;
a = b;
b = temp;
}
if (a > c) {
int temp = a;
a = c;
c = temp;
}
if (b > c) {
int temp = b;
b = c;
c = temp;
}
System.out.println("a=" + a);
System.out.println("b=" + b);
System.out.println("c=" + c);
}
}
把下面代码放到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);
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);
}
}
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个整数,分别赋给整数变量a b c 然后将输入的整数按照从小到大的顺序放在变量a b c中,并输三个变量的值。(各种情况都要算啊)最好源代码粘贴,复制到Eclipse
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);
}
阙浅肝达: import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.IOException; import java.util.Arrays;import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import ...
井陉矿区18943388597: 用Java、从键盘上输入3个整数,分别赋给整形变量a、b、c,然后将输入的 - ?
阙浅肝达: int a = 3, b = 4, c = 5; int[] array = new int[]{a, b, c}; java.util.Arrays.sort(array); //数组排序 a = array[0]; b = array[1]; c = array[2];
井陉矿区18943388597: 使用Java编写一个程序,使其从键盘上读取三个整数,并求和! - ?
阙浅肝达: import java.util.Scanner;public class A{ public static void main(String args[]){ Scanner input=new Scanner(System.in); double s=0; for(int i=1;i<=3;i++){ System.out.print("请输入第"+i+"个数:"); s+=input.nextInt(); } System.out.println("三个数的和"+s); }}
井陉矿区18943388597: 用java 从键盘输入3个整数,分别赋给整数变量a b c 然后将输入的整数按照从小到大的顺序放在变量abc中,并 - ?
阙浅肝达: 2L你好夸张抄! 把下面代码放到main()方法中 Scanner s=new Scanner(System.in); System.out.println("请输入a的值:zhidao"); int a=s.nextInt(); System.out.println("请输入b的值:"); int b=s.nextInt(); System.out.println("请输入c...
井陉矿区18943388597: 用java语言编程:从键盘输入三个整数,分别计算它们的平均值、累加和、最大值和最小值. - ?
阙浅肝达: package test;import java.util.Scanner;public class FindMaxAndMinInt { public static void main(String[] args) {int max=0,min=0,sum=0;double avg=0;Scanner scanner = new Scanner(System.in);for (int i = 0; i < 3; i++) {int tmp=0;//捕获异...
井陉矿区18943388597: java 程序从键盘输入三个数,将它们由小到大的顺序输出 - ?
阙浅肝达: //由于简单没加注释 import java.io.*; import java.util.StringTokenizer; public class Test {public Test() { } public static void main (String[] args) { System.out.println("Enter"); InputStreamReader isr = new InputStreamReader(System.in); ...
井陉矿区18943388597: 在JAVA里输入三个整数,判断它们能否组成一个三角形的思维和方法? - ?
阙浅肝达: 首先从键盘里输入三个整数,分别存放于变量a,b,c. 能组成一个三角形的条件是啥捏? 两边之和要大于第三边而且两边之差要小于第三边~所以即可用if语句来判断 if((a+b) > c && (a-b) < c) { System.out.println("这是一个三角形"); }else { System.out.println("这不是一个三角形"); }
井陉矿区18943388597: 从键盘输入3个整数,分别赋值给a、b、c,将输入的数按从小到大放在abc中,分别输出.要求使用import java.util.Scanner(从控制台输入); 使用if else选择... - ?
阙浅肝达:[答案] import java.util.Scanner;public class Demo {public static void main(String[] args) {int x = new Scanner(System.in).nextInt();int y = new Scanner(System.in).nextInt();int z = new Scanner(System.in).nex...
井陉矿区18943388597: 用java编写程序对三个整数排序,由键盘输入整数分别存入变量num1,num2,num3对他们进行排序,使得num1<=n - ?
阙浅肝达: 用 num1 = scanner.nextInt(); 分别去接受用户输入的三个数字;然后判断他们之间的大小后输出 . 如果你想num1 <=num2<=num3 , 那么你只需要将他们的位置换换就行啦!
井陉矿区18943388597: java编程用IF语句做的.从键盘输入任意三个整数,用IF条件语句来比效三个数的大小,按大到小的顺序输出. - ?
阙浅肝达: 1.读入三个数,存入数组numarr[];2.如果a>b,则a,b互换;3.如果a>c,则a,c互换;4.如果b>c,则b,c互换;5.输出c,b,a;即为从大到小的顺序.代码如下:import java.io.*; import java.util.Scanner; public class compare{ public static void main(...