JAVA输入三个整数abc
时间: 2024-06-06 11:08:55 浏览: 15
,求其最大值。
您好!对于您的问题,我可以给出以下JAVA代码:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int a = scanner.nextInt();
int b = scanner.nextInt();
int c = scanner.nextInt();
int max = a;
if (b > max) {
max = b;
}
if (c > max) {
max = c;
}
System.out.println("三个整数中最大的数是:" + max);
}
}
希望能对您有所帮助!
相关问题
输入三个整数abc,请把这三个数由小到大输出
输入三个整数abc,请把这三个数由小到大输出。
可以使用冒泡排序或者直接比较大小的方法实现。下面是直接比较大小的方法:
```
请输入三个数,用于把这三个数从小到大输出
请输入第一个数:
20
请输入第二个数:
10
请输入第三个数:
30
三个数从小到大排列是:[10, 20, 30]
```
代码如下:
```java
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
sort();
}
public static void sort(){
Scanner sc = new Scanner(System.in);
System.out.println("请输入三个数,用于把这三个数从小到大输出");
System.out.println("请输入第一个数:");
int a = sc.nextInt();
System.out.println("请输入第二个数:");
int b = sc.nextInt();
System.out.println("请输入第三个数:");
int c = sc.nextInt();
if(a>b){
int temp = a;
a = b;
b = temp;
}
if(b>c){
int temp = c;
c = b;
b = temp;
}
if(a>c){
int temp = a;
a = c;
c = temp;
}
System.out.println("三个数从小到大排列是:["+a+", "+b+", "+c+"]");
}
}
```
Java编程实现:从键盘上输人3 个整数,分别赋给整型变量 abc,然后将输入的整数按照从小到大的顺序放在变量 a、b、c中,并输出3个变量的值
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int a, b, c;
System.out.print("请输入三个整数:");
int abc = input.nextInt();
a = abc / 100; // 取百位数
b = abc / 10 % 10; // 取十位数
c = abc % 10; // 取个位数
if (a > b) { // 交换a和b的位置
int temp = a;
a = b;
b = temp;
}
if (a > c) { // 交换a和c的位置
int temp = a;
a = c;
c = temp;
}
if (b > c) { // 交换b和c的位置
int temp = b;
b = c;
c = temp;
}
System.out.println("a=" + a + " b=" + b + " c=" + c);
}
}
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)