25道经典Java算法题

您所在的位置:网站首页 java题目大全 25道经典Java算法题

25道经典Java算法题

#25道经典Java算法题| 来源: 网络整理| 查看: 265

即使做web开发,也会遇到各种各种需要解决的算法问题,本文节选部分经典练手算法,并提供相关参考答案,希望对你有所帮助【程序1】题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? //这是一个菲波拉契数列问题

public class test01 {public static void main(String[] args) {int f1=1,f2=1,f;int M=30;System.out.println(1);System.out.println(2);for(int i=3;i=60?'B':'C';System.out.println(grade);}}

【程序6】题目:输入两个正整数m和n,求其最大公约数和最小公倍数。 /*在循环中,只要除数不等于0,用较大数除以较小的数,将小的一个数作为下一轮循环的大数,取得的余数作为下一轮循环的较小的数,如此循环直到较小的数的值为0,返回较大的数,此数即为最大公约数,最小公倍数为两数之积除以最大公约数。 /

import java.util.Scanner;public class test06 {public static void main(String[] args) {Scanner input =new Scanner(http://System.in);int a=input.nextInt();int b=input.nextInt();test06 test=new test06();int i = test.gongyinshu(a, b);System.out.println("最小公因数"+i);System.out.println("最大公倍数"+a*b/i);}public int gongyinshu(int a,int b) {if(a


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3