两个java小程序
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了两个java小程序相关的知识,希望对你有一定的参考价值。
写了java才知道,python写起来真是爽啊
######################任意三个数排序####################################
import java.util.Scanner;
class SortNu
{
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
//获取三个数字
System.out.print("请输入第一个整数:");
int num1 = s.nextInt();
System.out.print("请输入第二个整数:");
int num2 = s.nextInt();
System.out.print("请输入第三个整数:");
int num3 = s.nextInt();
//比较流程
if (num1 >= num2)
{
//int imy_max = num1;
if (num1 >= num3)
{
int imy_max = num1;
if (num2 >= num3)
{
int imy_min = num3;
int imy_mid = num2;
System.out.println(imy_min);
System.out.println(imy_mid);
System.out.println(imy_max);;
}
else
{
int imy_min = num2;
int imy_mid = num3;
System.out.println(imy_min);
System.out.println(imy_mid);
System.out.println(imy_max);
}
}
else
{
int imy_max = num3;
int imy_mid = num1;
int imy_min = num2;
System.out.println(imy_min);
System.out.println(imy_mid);
System.out.println(imy_max);
}
//System.out.println(imy_min + "," + imymid + "," + imymax);
}
else
{
//int imy_max = num2;
if (num2 >= num3)
{
int imy_max = num2;
if (num1 >= num3)
{
int imy_min = num3;
int imy_mid = num1;
System.out.println(imy_min);
System.out.println(imy_mid);
System.out.println(imy_max);
}
else
{
int imy_min = num1;
int imy_mid = num3;
System.out.println(imy_min);
System.out.println(imy_mid);
System.out.println(imy_max);
}
//System.out.println(imy_min + "," + imymid + "," + imymax);
}
else
{
int imy_max = num3;
int imy_mid = num2;
int imy_min = num1;
System.out.println(imy_min);
System.out.println(imy_mid);
System.out.println(imy_max);
//System.out.println(imy_min + "," + imymid + "," + imymax);
}
}
}
}
###############################小明的分数##############################################
import java.util.Scanner;
class ScoreTest
{
public static void main(String[] alsrgs)
{
while (true)
{
Scanner s = new Scanner(System.in);
System.out.print("请输入小明的期末成绩:");
int score = s.nextInt();
if ( score == 100 )
{
System.out.println("恭喜你,获得宝马一辆。");
}
else if ( score >= 90 && score < 100 )
{
System.out.println("恭喜,获得手机一部");
}
else if (score >= 60 && score < 100 )
{
System.out.println("恭喜,获得图书一本");
}
else
{
System.out.println("你已无可救药了");
}
}
}
}
######################################################################################
以上是关于两个java小程序的主要内容,如果未能解决你的问题,请参考以下文章