上传文件至 /
This commit is contained in:
36
DaffodilsNum.java
Normal file
36
DaffodilsNum.java
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
public class DaffodilsNum {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Scanner in = new Scanner(System.in);
|
||||||
|
System.out.print("请输入0-1000内的数字: ");
|
||||||
|
int num = in.nextInt();
|
||||||
|
in.close();
|
||||||
|
|
||||||
|
// 1. 判断输入是否合法
|
||||||
|
if (num < 0 || num > 1000) {
|
||||||
|
System.out.println("输入的不是0-1000内的数字!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (num < 100 || num > 999) {
|
||||||
|
System.out.println(num + "不是水仙花数!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int ge = num % 10;
|
||||||
|
int shi = num / 10 % 10;
|
||||||
|
int bai = num / 100;
|
||||||
|
|
||||||
|
|
||||||
|
int sum = ge * ge * ge + shi * shi * shi + bai * bai * bai;
|
||||||
|
|
||||||
|
|
||||||
|
if (sum == num) {
|
||||||
|
System.out.println(num + "是水仙花数!");
|
||||||
|
} else {
|
||||||
|
System.out.println(num + "不是水仙花数!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
27
LeapYear.java
Normal file
27
LeapYear.java
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
public class LeapYear {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Scanner scan = new Scanner(System.in);
|
||||||
|
System.out.print("请输入2000~3000内的年数!");
|
||||||
|
int year = scan.nextInt();
|
||||||
|
scan.close();
|
||||||
|
|
||||||
|
|
||||||
|
if (year < 2000 || year > 3000) {
|
||||||
|
System.out.println("请输入2000~3000内的年数!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
boolean isLeap = false;
|
||||||
|
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
|
||||||
|
isLeap = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (isLeap) {
|
||||||
|
System.out.println(year + "年是闰年");
|
||||||
|
} else {
|
||||||
|
System.out.println(year + "年不是闰年");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
40
javaclass.java
Normal file
40
javaclass.java
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import java.util.Scanner;
|
||||||
|
import java.lang.Math;
|
||||||
|
class EquationRoot
|
||||||
|
{
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
Scanner scan = new Scanner(System.in);
|
||||||
|
double a,b,c,disc,x1,x2,p,q;
|
||||||
|
|
||||||
|
System.out.print("请输入系数a=");
|
||||||
|
a = scan.nextDouble() ;
|
||||||
|
|
||||||
|
System.out.print("请输入系数b=");
|
||||||
|
b = scan.nextDouble() ;
|
||||||
|
|
||||||
|
System.out.print("请输入系数c=");
|
||||||
|
c = scan.nextDouble() ;
|
||||||
|
|
||||||
|
disc=b*b-4*a*c;
|
||||||
|
|
||||||
|
if ( Math.abs(disc) <= 1e-6 )
|
||||||
|
System.out.println("x1=x2="+(-b/(2*a)));
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(disc>1e-6)
|
||||||
|
{
|
||||||
|
x1=(-b+Math.sqrt(disc))/(2*a);
|
||||||
|
x2=(-b-Math.sqrt(disc))/(2*a);
|
||||||
|
System.out.printf("x1=%7.2f,x2=%7.2f\n", x1, x2);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
p=-b/(2*a);
|
||||||
|
q=Math.sqrt(Math.abs(disc))/(2*a);
|
||||||
|
System.out.printf("x1=%7.2f + %7.2f i\n", p, q);
|
||||||
|
System.out.printf("x2=%7.2f - %7.2f i\n", p, q);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
23
javaclass2.java
Normal file
23
javaclass2.java
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
class ScoreToGrade
|
||||||
|
{
|
||||||
|
public static void main(String[] args)
|
||||||
|
{
|
||||||
|
Scanner scan = new Scanner(System.in);
|
||||||
|
int i_score;
|
||||||
|
System.out.print("请输入分数 = ");
|
||||||
|
i_score = scan.nextInt();
|
||||||
|
i_score /=10;
|
||||||
|
|
||||||
|
switch(i_score)
|
||||||
|
{
|
||||||
|
case 10:
|
||||||
|
case 9:System.out.println("成绩为 优秀 !"); break;
|
||||||
|
case 8:System.out.println("成绩为 良好 !"); break;
|
||||||
|
case 7:System.out.println("成绩为 中等 !"); break;
|
||||||
|
case 6:System.out.println("成绩为 及格 !"); break;
|
||||||
|
default:System.out.println("成绩为 不及格 !");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user