帮我用java写一个小程序 功能:用户随便输入4个数字,输出最小的那个数
答案:1 悬赏:0 手机版
解决时间 2021-04-06 12:21
- 提问者网友:最美的风景
- 2021-04-05 13:45
帮我用java写一个小程序 功能:用户随便输入4个数字,输出最小的那个数
最佳答案
- 五星知识达人网友:孤老序
- 2021-04-05 14:55
System.out.println("请分别输入四个不同的数字:" );
Scanner scanner = new Scanner(System.in);
int a ,b,c,d;
a = scanner.nextInt();
b = scanner.nextInt();
c = scanner.nextInt();
d = scanner.nextInt();
scanner.close();
int min = a ;
if(min > b)
{
min = b;
}
if(min > c)
{
min = c;
}
if(min > d)
{
min = d;
}
System.out.println("min = " + min);简单的代码,不是完整的可运行的,需要加上JAVA的类和主函数
追问:帮我加上吧
追答:import java.util.Scanner;
public class Demo
{
public static void main(String[] args) {
System.out.println("请分别输入四个不同的数字:" );
Scanner scanner = new Scanner(System.in);
int a ,b,c,d;
a = scanner.nextInt();
b = scanner.nextInt();
c = scanner.nextInt();
d = scanner.nextInt();
scanner.close();
int min = a ;
if(min > b)
{
min = b;
}
if(min > c)
{
min = c;
}
if(min > d)
{
min = d;
}
System.out.println("min = " + min);
}
}
Scanner scanner = new Scanner(System.in);
int a ,b,c,d;
a = scanner.nextInt();
b = scanner.nextInt();
c = scanner.nextInt();
d = scanner.nextInt();
scanner.close();
int min = a ;
if(min > b)
{
min = b;
}
if(min > c)
{
min = c;
}
if(min > d)
{
min = d;
}
System.out.println("min = " + min);简单的代码,不是完整的可运行的,需要加上JAVA的类和主函数
追问:帮我加上吧
追答:import java.util.Scanner;
public class Demo
{
public static void main(String[] args) {
System.out.println("请分别输入四个不同的数字:" );
Scanner scanner = new Scanner(System.in);
int a ,b,c,d;
a = scanner.nextInt();
b = scanner.nextInt();
c = scanner.nextInt();
d = scanner.nextInt();
scanner.close();
int min = a ;
if(min > b)
{
min = b;
}
if(min > c)
{
min = c;
}
if(min > d)
{
min = d;
}
System.out.println("min = " + min);
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯