1 一个整数,它加上100或者268后都是一个完全平方数,请问在1万以内,这样的数有几个,分别是多 少
public class Test9 {
public static void main(String[] args) {
for (int k = 1; k < 10000; k++) {
int k1=k+100;
boolean bb1=false;
int dd = (int) Math.sqrt(k1);
if (dd * dd == k1) {
bb1=true;
}
int k2=k+268;
dd = (int) Math.sqrt(k1);
boolean bb2=false;
if (dd * dd == k1) {
bb2=true;
}
if(bb1||bb2) {
System.out.println(k);
}
}
}
}
2.有一分数序列:2/1,3/2,5/3,8/5,13/8,21/13。求出这个数列的前20项之和。
public class Test5 {
public static void main(String[] args) {
int n1 =2,n2=3;
int n3=1,n4=2;
int n=0;
int m=0;
double sum=1.*n1/n3+1.*n2/n4;
for(int i=3;i<21;i++) {
n=n1+n2;
m=n3+n4;
System.out.println(n+"/"+m);
sum+=1.*n/m;
n1=n2;
n3=n4;
n2=n;
n4=m;
}
System.out.println(sum);
}
}
3.输入三个数判断这三个数是否可以租成一个三角形,是什么三角形。
public class Teat7 {
public static void main(String[] args) {
int a=0,b=0,c=0;
Scanner sc= new Scanner(System.in);
System.out.println("请输入第一边长度为:");
while(true){
a=sc.nextInt();
if(a>=1&& a<100)
break;
else
System.out.println("输入错误");
}
System.out.println("请输入第二边长度为:");
while(true){
b=sc.nextInt();
if(b>=1&& b<100)
break;
else
System.out.println("输入错误");
}
System.out.println("请输入第三边长度为:");
while(true){
c=sc.nextInt();
if(c>=1&& c<100)
break;
else
System.out.println("输入错误");
}
boolean sanjiao = (a+b>c)&&(a+c>b)&&(c+b>a);
if (sanjiao) {
if (a == b && b == c) {
System.out.println("等边三角形");
} else if (a == b || b == c || a == c) {
System.out.println("等腰三角形");
} else if (a * a + b * b == c * c || a * a + c * c == b * b || b * b + c * c == a * a) {
System.out.println("直角三角形");
} else
System.out.println("普通三角型");
} else {
System.out.println("不是三角型");
}
}
}