Skip to content

Commit c78f8c0

Browse files
committed
算法
1 parent cde64c2 commit c78f8c0

13 files changed

+160
-0
lines changed

.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>Algorithm40</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>

.settings/org.eclipse.jdt.core.prefs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=1.8
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11+
org.eclipse.jdt.core.compiler.source=1.8

bin/ConditionUse.class

1.02 KB
Binary file not shown.

bin/Daffodil.class

722 Bytes
Binary file not shown.

bin/MyMath.class

473 Bytes
Binary file not shown.

bin/PrimeDivide.class

1.21 KB
Binary file not shown.

bin/PrimeNumber.class

1003 Bytes
Binary file not shown.

bin/RabbitBirth.class

735 Bytes
Binary file not shown.

src/ConditionUse.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import java.util.Scanner;
2+
3+
public class ConditionUse {
4+
5+
public static void main(String[] args) {
6+
// TODO Auto-generated method stub
7+
8+
System.out.println("input the score:");
9+
Scanner sc=new Scanner(System.in);
10+
int score=sc.nextInt();
11+
evaluate(score);
12+
sc.close();
13+
System.exit(0);
14+
15+
16+
}
17+
18+
public static void evaluate(int score){
19+
String str=(score>90?"A":(score>60?"B":"C"));
20+
System.out.println(str);
21+
}
22+
23+
}

src/Daffodil.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* 打印出所有的 "水仙花数 ",所谓 "水仙花数 "是指一个
3+
* 三位数,其各位数字立方和等于该数本身。例如:153是一个 "水仙花数 ",因为153=1的三次方+5的三次方+3的三次方。
4+
*/
5+
public class Daffodil {
6+
7+
public static void main(String[] args) {
8+
// TODO Auto-generated method stub
9+
System.out.println("hh");
10+
MyMath mymath=new MyMath();
11+
for(int i=100;i<1000;i++){
12+
if(mymath.isDaffodil(i)==true)
13+
System.out.println(i);
14+
}
15+
16+
17+
}
18+
}
19+
class MyMath{
20+
public boolean isDaffodil(int number){
21+
int s=0;
22+
int count=0;
23+
while(number!=0){
24+
s= number%10;
25+
count=count+s*s*s;
26+
number=number/10;
27+
}
28+
return count==number;
29+
}
30+
}

src/PrimeDivide.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import java.util.Scanner;
2+
3+
public class PrimeDivide {
4+
5+
public static void main(String[] args) {
6+
// TODO Auto-generated method stub
7+
8+
Scanner sc=new Scanner(System.in);
9+
System.out.println("input the number:");
10+
int number=sc.nextInt();
11+
divide(number);
12+
sc.close();
13+
}
14+
15+
public static void divide(int number){
16+
for(int i=2;i<=number/2;i++){
17+
while(number%i==0){
18+
number/=i;
19+
System.out.print(i+"*");
20+
}
21+
}
22+
System.out.print(number);
23+
}
24+
25+
}

src/PrimeNumber.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* 判断101-200之间有多少个素数,并输出所有素数。
3+
*/
4+
public class PrimeNumber {
5+
public static void main(String[]args){
6+
int primeNumber=0,index=0;
7+
int a[]=new int[100];
8+
for(int i=101;i<=200;i++){
9+
if(isPrime(i)==true){
10+
primeNumber++;
11+
a[index]=i;
12+
index++;
13+
}
14+
}
15+
System.out.println(primeNumber);
16+
for(int i=0;i<index;i++)
17+
System.out.println(a[i]);
18+
}
19+
20+
public static boolean isPrime(int number){
21+
boolean primeflag=true;
22+
for(int i=2;i<=Math.sqrt(number);i++){
23+
if(number%i==0){
24+
primeflag=false;
25+
break;
26+
}
27+
}
28+
return primeflag;
29+
}
30+
}

src/RabbitBirth.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第四
3+
* 个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少?
4+
*/
5+
6+
public class RabbitBirth {
7+
public static void main(String[] args){
8+
int month=1;
9+
for(int i=1;i<20;i++){
10+
System.out.println(FeiBoCount(month));
11+
month++;
12+
}
13+
}
14+
15+
public static int FeiBoCount(int month){
16+
if(month==1||month==2)
17+
return 1;
18+
else
19+
return FeiBoCount(month-1)+FeiBoCount(month-2);
20+
21+
}
22+
23+
}
24+

0 commit comments

Comments
 (0)