递归算法
import java.util.Scanner;
public class MainDemo
{
public static void main(String []args)
{
System.out.print("请输入数字");
Scanner input=new Scanner(System.in);
int n=input.nextInt();
for(int a=1;a<=2*n;a++){
if(a<=n){
int b=1;
while(b<=a){
System.out.print("*");
b++;
}
System.out.println(" ");
}
else{
int b=a;
while(b<2*n+1){
System.out.print("*");
b++;
}
System.out.println(" ");
}
}
}
}
斐波数列
public class Test {
public static void main(String[] args) {
List<Long> list = new ArrayList<Long>();
int i = 1;
while(i <= 100){
if(i <= 2){
list.add(new Long(1));
}else{
long value = list.get(i-2) + list.get(i - 3);
list.add(new Long(value));
}
i++;
}
int count = 1;
for(i = 0; i < list.size(); i++){
if(count == 5){
System.out.println();
count = 0;
}
System.out.print(list.get(i).longValue() + " ");
count++;
}
}
}
import java.util.Scanner;
public class MainDemo
{
public static void main(String []args)
{
System.out.print("请输入数字");
Scanner input=new Scanner(System.in);
int n=input.nextInt();
for(int a=1;a<=2*n;a++){
if(a<=n){
int b=1;
while(b<=a){
System.out.print("*");
b++;
}
System.out.println(" ");
}
else{
int b=a;
while(b<2*n+1){
System.out.print("*");
b++;
}
System.out.println(" ");
}
}
}
}
斐波数列
public class Test {
public static void main(String[] args) {
List<Long> list = new ArrayList<Long>();
int i = 1;
while(i <= 100){
if(i <= 2){
list.add(new Long(1));
}else{
long value = list.get(i-2) + list.get(i - 3);
list.add(new Long(value));
}
i++;
}
int count = 1;
for(i = 0; i < list.size(); i++){
if(count == 5){
System.out.println();
count = 0;
}
System.out.print(list.get(i).longValue() + " ");
count++;
}
}
}