当前位置:编程学习 > JAVA >>

java经典笔试50题(含答案,前25题)

--------------------编程问答-------------------- 第十一题

package com.supersoft.exercise;

/**
 * @author JamesLiu
 * 
 * 【程序11】
 * 题目:有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?
 *       1.程序分析:可填在百位、十位、个位的数字都是1、2、3、4。
 *    组成所有的排列后再去 掉不满足条件的排列。
 */
public class ProgramEx11 {

public static void main(String[] args) {
int sum = 0;
int m = 0;
for (int a=1; a<=4; a++) {
for (int b=1; b<=4; b++) {
if (a!=b) {
for (int c=1; c<=4; c++) {
if (b!=c && a!=c) {
m = a*100 + b*10 +c;
sum = sum + 1;
System.out.print(m+" ");
//System.out.print(a+""+b+""+c);
}
}
}
}
}
System.out.println("一共有"+sum+"个");

}

}


第十二题

package com.supersoft.exercise;

/**
 * @author JamesLiu
 *
 *【程序12】
 * 题目:企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高于10万元,低于20万
 * 元时,低于10万元的部分按10%提成,高于10万元的部分,可可提成7.5%;20万到40万之间时,高于20万元的部
 * 分,可提成5%;40万到60万之间时高于40万元的部分,可提成3%;60万到100万之间时,高于60万元的部分,可
 * 提成1.5%,高于100万元时,超过100万元的部分按1%提成,从键盘输入当月利润I,求应发放奖金总数?
 * 1.程序分析:请利用数轴来分界,定位。注意定义时需把奖金定义成长整型。
 */
import java.util.Scanner;

public class ProgramEx12 {

public static void main(String[] args) {
System.out.print("请输入利润(注:利润>0):");
Scanner scanner = new Scanner(System.in);
int m = scanner.nextInt();
long n = 0L;
if (m<=10) {
n = (long)(0.1 * m);
}
else if (m<=20) {
n = (long)(1 + (m-10)*0.075);
}
else if (m<=40) {
n = (long)(1.75 + (m-20)*0.05);
}
else if (m<=60) {
n = (long)(1.85 + (m-40)*0.03);
}
else {
n = (long)(1.91 + (m-60)*0.01);
}
System.out.print("所得奖金为:"+n+"万元");
}

}


第十三题

package com.supersoft.exercise;

/**
 * @author JamesLiu
 *
 *【程序13】
 * 题目:一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?
 * 1.程序分析:在10万以内判断,先将该数加上100后再开方,再将该数加上268后再开方,如果开方后的结果满足
 * 如下条件,即是结果。
 */
public class ProgramEx13 {

public static void main(String[] args) {
long x, y;
for (long i=1; i<100000;i++) {
x = (long)Math.sqrt(i+100);
y = (long)Math.sqrt(i+268);

if (x*x == (i+100) && y*y == (i+268)) {
System.out.println(i);
}
}
}

}

第十四题

package com.supersoft.exercise;

/**
 * @author JamesLiu
 *
 *【程序14】
 * 题目:输入某年某月某日,判断这一天是这一年的第几天?
 *   1.程序分析:以3月5日为例,应该先把前两个月的加起来,然后再加上5天即本年的第几天,特殊情况,闰年且
 *        输入月份大于3时需考虑多加一天。
 */
 import java.util.Scanner;
 
 public class ProgramEx14 {
 
  public static void main(String[] args) {
  System.out.print("请输入年year:");
  Scanner scanner = new Scanner(System.in);
  int y = scanner.nextInt();
  System.out.print("请输入月month:");
  int m = scanner.nextInt();
  System.out.print("请输入日day:");
  int d = scanner.nextInt();
  int sum = 0;
  for (int i=1; i<m; i++) {
  if ((i==4) || (i==6) || (i==9) || (i==11)) {
  sum = sum + 30;
  }
  else if (i==2) {
  if (((y%4==0 && y%100!=0) || (y%400==0))) {
  sum = sum + 29;
  }
  else {
  sum = sum + 28;
  }
  }
  else {
  sum = sum + 31;
  }
  }
  sum = sum + d;
  System.out.print("这一天是这一年中的第"+sum+"天");
  }
 } 
 


/*
import java.util.Scanner;

public class ProgramEx14 {

public static boolean isValidate(int y, int m, int d, int[] monthOfDays) {
if (y<=0) {
return false;
}
if (m<=0 || m>12) {
return false;
}
if (d<=0 || d>monthOfDays[m-1]) {
return false;
}
return true;
}

public static void main(String[] args) {

System.out.print("请输入年year:");
Scanner scanner = new Scanner(System.in);
int y = scanner.nextInt();
System.out.print("请输入月month:");
int m = scanner.nextInt();
System.out.print("请输入日day:");
int d = scanner.nextInt();

int[] monthOfDays = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if (((y%4==0 && y%100!=0) || (y%400==0))) {
monthOfDays[1] = 29;
}

if (isValidate(y, m, d, monthOfDays) == false) {
System.out.println("");
return;
}

int sum = 0;
for (int i=0; i<m-1; i++) {
sum = sum + monthOfDays[i];
}
sum = sum + d;
System.out.println("这一天是这一年的第"+sum+"天");
}
}
*/


第十五题

package com.supersoft.exercise;

/**
 * @author JamesLiu
 *
 *【程序15】
 * 题目:输入三个整数x,y,z,请把这三个数由小到大输出。
 * 1.程序分析:我们想办法把最小的数放到x上,先将x与y进行比较,如果x>y则将x与y的值进行交换,然后再用x
 *         与z进行比较,如果x>z则将x与z的值进行交换,这样能使x最小。
 */
import java.util.Scanner;

public class ProgramEx15 {

public static void main(String[] args) {
System.out.println("请输入三个整数x,y,z:");
Scanner scanner = new Scanner(System.in);
int x = scanner.nextInt();
int y = scanner.nextInt();
int z = scanner.nextInt();
if (x>y) {
int m = x;
x = y;
y = m;
}

if (x>z) {
int p = x;
x = z;
z = p;
}

if (y>z) {
int n = y;
y = z;
z = n;
}

System.out.print(x+","+y+","+z);
}
}

第十六题

package com.supersoft.exercise;

/**
 * @author JamesLiu
 *
 *【程序16】
 * 题目:输出9*9口诀。
 *  1.程序分析:分行与列考虑,共9行9列,i控制行,j控制列。
 */
public class ProgramEx16 {

public static void main(String[] args) {
for (int i=1; i<=9; i++) {
for (int j=1; j<=i; j++) {
System.out.print(" "+i+"*"+j+"="+i*j+'\t');
}
System.out.println();
}
}
}

第十七题

package com.supersoft.exercise;

/**
 * @author JamesLiu
 *
 *【程序17】
 * 题目:猴子吃桃问题:猴子第一天摘下若干个桃子,当即吃了一半,还不瘾,又多吃了一个 第二天早上又将剩
 *    下的桃子吃掉一半,又多吃了一个。以后每天早上都吃了前一天剩下
 *    的一半零一个。到第10天早上想再吃时,见只剩下一个桃子了。求第一天共摘了多少。
 *  1.程序分析:采取逆向思维的方法,从后往前推断。
 */
public class ProgramEx17 {

public static void main(String[] args) {
int m = 1;
for (int i=1; i<10; i++) {
m = (m+1)*2;
}
System.out.print("第一天共摘了"+m+"只桃子");
}
}

第十八题

package com.supersoft.exercise;

/**
 * @author JamesLiu
 *
 *【程序18】
 * 题目:两个乒乓球队进行比赛,各出三人。甲队为a,b,c三人,乙队为x,y,z三人。已抽签决定比赛名单。有人向
 * 队员打听比赛的名单。a说他不和x比,c说他不和x,z比,请编程序找出三队赛手的名单。
 * 1.程序分析:判断素数的方法:用一个数分别去除2到sqrt(这个数),如果能被整除, 则表明此数不是素数,反
 * 之是素数。
 */

public class ProgramEx18 {

public static void main(String[] args) {
String[] m = {"a", "b", "c"};
String[] n = {"x", "y", "z"};
for (int i=0; i<3; i++) {
for (int j=0; j<3; j++) {
if (!(i==0 && j==0) && !(i==2 && (j==1 || j==2))) {
System.out.println(m[i]+"和"+n[j]+"比赛");
}
}
}
}
}


第十九题

package com.supersoft.exercise;

/**
 * @author JamesLiu
 *
 *【程序19】
 * 题目:打印出如下图案(菱形)
 *     *
 *    ***
 *   *****
 *  *******
 *   *****
 *    ***
 *     *
 * 1.程序分析:先把图形分成两部分来看待,前四行一个规律,后三行一个规律,利用双重 for循环,第一层控制
 *                     行,第二层控制列。
 *
public class ProgramEx19 {

public static void main(String[] args) {
for (int i=1; i<=4; i++) {
for (int j=1; j<=4-i; j++) {
System.out.print(" ");
}
for (int j=1; j<=2*i-1; j++) {
System.out.print("*");
}
System.out.println();
}
for (int i=3; i>=1; i--) {
for (int j=1; j<=4-i; j++) {
System.out.print(" ");
}
for (int j=1; j<=2*i-1; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
*/


public class ProgramEx19 {

public static void main(String[] args) {
int n = 0;
for (int i=0; i<7; i++) {
for (int j=0; j<4+n; j++) {
if (j<3-i || j<i-3) {
System.out.print(" ");
}
else {
System.out.print("*");
}
}
if (i<3) {
n++;
}
else {
n--;
}
System.out.println();
}
}
}


第二十题

package com.supersoft.exercise;

/**
 * @author JamesLiu
 *
 *【程序20】
 * 题目:有一分数序列:2/1,3/2,5/3,8/5,13/8,21/13...求出这个数列的前20项之和。
 *  1.程序分析:请抓住分子与分母的变化规律。
 */
public class ProgramEx20 {

public static void main(String[] args) {

double result = 0;
double a = 2.0;
double b = 1.0;
for (int i=1; i<=20; i++) {
result = result + a/b;
double m = b;
b = a;
a = a+m;
}
System.out.print(result);
}
}

--------------------编程问答-------------------- 第二十一题

package com.supersoft.exercise;

/**
 * @author JamesLiu
 *
 *【程序21】
 * 题目:求1+2!+3!+...+20!的和
 */
public class ProgramEx21 {

public static void main(String[] args) {
int result = 0;
int m = 1;
for (int i=1; i<=20; i++) {
m = m*i;
result = result + m;
}
System.out.print(result);
}
}

第二十二题

package com.supersoft.exercise;

/**
 * @author JamesLiu
 *
 *【程序22】
题目:利用递归方法求5!。
1.程序分析:递归公式:fn=fn_1*4!
 *
public class ProgramEx22 {

public static void main(String[] args) {
int m = 1;
for (int i=1; i<=5; i++) {
m = m * i;
}
System.out.print(m);
}
}
*/

public class ProgramEx22 {
public static void main(String[] args) {
System.out.print(f(5));
}

public static int f(int n) {
if (n==0) {
return 1;
}
return n*f(n-1);
}
}

第二十三题

package com.supersoft.exercise;

/**
 * @author JamesLiu
 *
 *【程序23】
 * 题目:有5个人坐在一起,问第五个人多少岁?他说比第4个人大2岁。问第4个人岁数,他说比第3个人大2岁。问
 * 第三个人,又说比第2人大两岁。问第2个人,说比第一个人大两岁。最后问第一个人,他说是10岁。请问第五个
 * 人多大?
 * 1.程序分析:利用递归的方法,递归分为回推和递推两个阶段。要想知道第五个人岁数,需知道第四人的岁数,
 * 依次类推,推到第一人(10岁),再往回推。
 */
public class ProgramEx23 {

public static void main(String[] args) {

System.out.print(f(5));
}

public static int f(int n) {

if (n==1) {
return 10;
}
return f(n-1) + 2;
}
}


第二十四题

package com.supersoft.exercise;

/**
 * @author JamesLiu
 *
 *【程序24】
 * 题目:给一个不多于5位的正整数,要求:一、求它是几位数,二、逆序打印出各位数字。
 *
import java.util.Scanner;

public class ProgramEx24 {

public static void main(String[] args) {
System.out.print("请输入一个不多于五位的正整数:");
Scanner scanner = new Scanner(System.in);
String str = scanner.next();
String[] strNum = str.split("");
int length = strNum.length - 1;
System.out.println("长度为:"+length);
System.out.print("逆序输出:");

for (int i=length-1; i>=0; i--) {
String m = strNum[i];
strNum[i] = strNum[length-i];
strNum[length-i] = m;
System.out.print(str.charAt(i));
}
}
}
*/

import java.util.Scanner;

public class ProgramEx24 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
Integer number = scanner.nextInt();
int length = number.toString().length();
System.out.print("该整数是"+length+"位数");

for (int i=length-1; i>=0; i--) {
System.out.print(number.toString().charAt(i));
}

}
}

第二十五题

package com.supersoft.exercise;

/**
 * @author JamesLiu
 *
 *【程序25】
 * 题目:一个5位数,判断它是不是回文数。即12321是回文数,个位与万位相同,十位与千位相同。
 *
import java.util.Scanner;

public class ProgramEx25 {

public static void main(String[] args) {
System.out.print("请输入一个五位数");
Scanner scanner = new Scanner(System.in);
int a = scanner.nextInt();
int m1 = a/10000;
int m2 = a%10;
int n1 = a%10000/1000;
int n2 = a%100/10;

if (m1==m2 && n1==n1) {
System.out.print("是回文字符串");
}
else {
System.out.print("不是回文字符串");
}

}
}
*/
import java.util.Scanner;

public class ProgramEx25 {
public static void main(String[] args) {
System.out.print("请输入一个五位数");
Scanner scanner = new Scanner(System.in);
String str = scanner.next();
int sum = 0;
for (int i=0; i<str.length()/2; i++) {
if(str.charAt(i) == str.charAt(str.length()-1-i)) {
sum = sum + 1;
}
}
if (sum == 2) {
System.out.print("是回文字符串");
}
else {
System.out.print("不是回文字符串");
}

}
}
--------------------编程问答-------------------- 感谢楼主,我做个研究先 --------------------编程问答-------------------- --------------------编程问答-------------------- --------------------编程问答-------------------- 强大的算法题。。。
以前很多都做过,现在大部分都忘了。 --------------------编程问答-------------------- --------------------编程问答-------------------- 就25道? 不是50道么? --------------------编程问答--------------------
引用 8 楼 zn85600301 的回复:
就25道? 不是50道么?

csdn 字数限制,么来得及放上去 --------------------编程问答-------------------- 有的的确经常遇到。 --------------------编程问答-------------------- --------------------编程问答-------------------- --------------------编程问答-------------------- mark 坐等50道题 --------------------编程问答-------------------- mark! --------------------编程问答-------------------- --------------------编程问答-------------------- --------------------编程问答-------------------- --------------------编程问答-------------------- 楼主啊 话说144648357这个群 为啥我加进去了一天后又被踢了呢?
我加进去时只有13个人。 --------------------编程问答-------------------- 我们公司的代码题只要求写个冒泡,没必要难为应聘的。 --------------------编程问答-------------------- 等LZ的后25题~ --------------------编程问答-------------------- 要是我面试写这种代码的人,先不管代码有否能得出结果,肯定直接就踢了

用OO的语言,还在写诸如:a*a*a 这种代码,Math类用不来啊?

还有  char n = (m<60)?"c":((m>=90)?"a":"b") 这行代码不报错吗?


等等等等..... --------------------编程问答-------------------- 这个真是不错,谢谢楼主!!3q  you !!! --------------------编程问答-------------------- --------------------编程问答--------------------
引用 21 楼 ft4185240 的回复:
要是我面试写这种代码的人,先不管代码有否能得出结果,肯定直接就踢了

用OO的语言,还在写诸如:a*a*a 这种代码,Math类用不来啊?

还有 char n = (m<60)?"c":((m>=90)?"a":"b") 这行代码不报错吗?


等等等等.....

+1
--------------------编程问答--------------------
引用 21 楼 ft4185240 的回复:
要是我面试写这种代码的人,先不管代码有否能得出结果,肯定直接就踢了

用OO的语言,还在写诸如:a*a*a 这种代码,Math类用不来啊?

还有 char n = (m<60)?"c":((m>=90)?"a":"b") 这行代码不报错吗?


等等等等.....

 此人为一个装逼的SB,鉴定完毕!!!
即使你技术再牛,没有哪家刚要你。。。
谁跟你说用了Math就OO了,装逼别处装。。。
char n=""莫非没学过java吗,不知道这是笔误?
等等等等.....
--------------------编程问答-------------------- thanks  for  short --------------------编程问答-------------------- --------------------编程问答-------------------- 楼主辛苦!收藏备用! --------------------编程问答-------------------- 楼主很有耐心嘛,呵呵!! --------------------编程问答-------------------- 感觉都是数学题
--------------------编程问答-------------------- 执行的版本号? --------------------编程问答-------------------- --------------------编程问答-------------------- 楼主的第一题错了吧? 
    题说是一对,然后问总数啊。一对就是两个。
 错了! --------------------编程问答-------------------- 初学java ,准备加你们的群,望收纳。此篇章收藏,慢慢研读!!!谢谢诶 --------------------编程问答-------------------- package com.supersoft.exercise;

/**
 * @author JamesLiu
 *
 *【程序6】
 *    题目:输入两个正整数m和n,求其最大公约数和最小公倍数。
 *         1.程序分析:利用辗除法。
 */
import java.util.Scanner;

public class ProgramEx6 {

    public static void main(String[] args) throws Exception {

        System.out.print("请输入两个整数");
        Scanner scan = new Scanner(System.in);
        int m = scan.nextInt();
        int n = scan.nextInt();

        int a, b;
        if (m<n) {
            b = m;
            m = n;
            n = b;
        }
        a = m%n;
        while(a!=0) {
            m = n;
            n = a;
            a = m%n;
            m = m*n;
        }

        System.out.println("最小公倍数为:"+m);
        //System.out.println("最大公约数为:"+n);
    }

}
我发现这个有点小bug主要是 m的值不正确
我小小改动了一下 不知道符合要求不  希望指正哟
import java.util.*;
public class ProgramEx6 {

    public static void main(String[] args) throws Exception {

        System.out.print("请输入两个整数");
        Scanner scan = new Scanner(System.in);
        int m = scan.nextInt();
        int n = scan.nextInt();

        int total = m*n;
        int a, b;
        if (m<n) {
            b = m;
            m = n;
            n = b;
        }
        a = m%n;
        while(a!=0) {
            m = n;
            n = a;
            a = m%n;
        }

        System.out.println("最小公倍数为:"+ total/n);
        System.out.println("最大公约数为:"+n);
    }

}

--------------------编程问答-------------------- --------------------编程问答-------------------- 看着还不错! --------------------编程问答-------------------- --------------------编程问答-------------------- 学习学习
--------------------编程问答-------------------- --------------------编程问答-------------------- 实际开发中貌似没啥用 --------------------编程问答-------------------- 还有二十五题呢.. --------------------编程问答-------------------- 初学,吸纳。。。 --------------------编程问答-------------------- --------------------编程问答-------------------- --------------------编程问答-------------------- --------------------编程问答-------------------- 不错。学些了。 --------------------编程问答-------------------- 好东东~~~~~~~~ --------------------编程问答-------------------- mark一吓
--------------------编程问答-------------------- 第一个算法有问题

有一对兔子,从出生后第3个月起每个月都生一对兔子,

你的算法是按照刚开始1只兔子,生出来的也是1只(兔子可不是雌雄同体,他们也要xxoo,呵呵)

其他算法:
其实没那么麻烦,
掌握规律之后你会发现这个规律其实就是裴波纳契级数,
运用递归算法很容易就能得出答案
算法:

import java.util.Scanner;

public class RubbitsumQuestion {

public static void main(String[] args) {
while(true){
System.out.print("请输入您要查看的月份:");
Scanner scan=new Scanner(System.in);
int month=3;
try{
month=scan.nextInt();
if(month<=0){
throw new Exception();
}
}catch (Exception e) {
System.out.print("您的输入有误,请重新输入:");
continue;
}
int rubbitsum=computeCount(month);
System.out.println("第"+month+"个月时,兔子总数为:"+rubbitsum);
}
}
//递归算法计算裴波纳契级数
public static int computeCount(int month){
if(month==1||month==2){
return 2;
}else{
return computeCount(month-1)+computeCount(month-2);
}
}

}

--------------------编程问答-------------------- --------------------编程问答-------------------- mark一下,感觉好多算法其实思想并不难,但是全掌握了也不容易,编去了。。。 --------------------编程问答-------------------- 第六题~ --------------------编程问答-------------------- --------------------编程问答-------------------- 楼主抓紧时间放上去其余问题哦,呵呵
顶一个!!!
--------------------编程问答-------------------- --------------------编程问答-------------------- --------------------编程问答-------------------- 请问为什么这些题的代码我在ECLIPSE或者记事本都会出现
Exception in thread "main" java.lang.Error: Unresolved compilation problem: 

at ProgramEx1.main(ProgramEx1.java:13)
这个错误呢?问题都指向MAIN那行,我是新人 --------------------编程问答-------------------- 用记事本就这样
Exception in thread "main" java.lang.NoClassDefFoundError: test
Caused by: java.lang.ClassNotFoundException: test
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: test.  Program will exit.

--------------------编程问答-------------------- --------------------编程问答-------------------- --------------------编程问答-------------------- 不错! 哦? --------------------编程问答-------------------- --------------------编程问答-------------------- --------------------编程问答-------------------- 第6题貌似不对把,不知道是我弄错了,还是楼主弄错了啊 --------------------编程问答-------------------- 第十题其实不对。LZ在仔细想想 --------------------编程问答--------------------

public class ProgramEx10 {

    public static void main(String[] args) {
        
        double height = 0;
        double h = 100;
        for (int i=1; i<=10; i++) {
    height += h; 
            h = 0.5 * h;
            height = height + h;
        
        System.out.println(i+"次一共经过"+height+"米");
        System.out.println("第"+i+"次反弹"+h+"米");
     }
    }

} --------------------编程问答-------------------- 好东西
--------------------编程问答-------------------- 楼主犀利 --------------------编程问答-------------------- --------------------编程问答--------------------
引用楼主 jamesliulyc 的回复:
以下答案源于java菜鸟学堂(144648357)群共享
第一题

Java code

package com.supersoft.exercise;

/**
 * @author JamesLiu
 * 
 * 【程序1】
 *     题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一
 *           对兔子……

本人学过一段时间java,也不怎么样。但自我认为这题的算法是点问题,若说错了请高手指教;我对题目理解如下:
从开始落下,第一次弹起高度为50M,落地时有经过50M,即第一次弹起经过的路程为100M,以后每次弹起经过的路程为前一次弹起的高度,但楼主这样写“h=0.5*h(这里没问题);heigth=heigth+h(这里是不是该将h*2,我们做个假设:假设第一次弹起落地就被粘住了那它经过的路程应该是200M,而按楼主的写法却只有150M,第二次弹起的高为25M,同样经过的路程是50M.....依次到第10次)”所以我认为这里该这样写:
h=h*0.5;heigth=heigth+h*2;我根据自己的理解来写,请高手指教!!!! --------------------编程问答-------------------- 哦不好意思这里引错了,是对第10题说的

package com.supersoft.exercise;

/**
 * @author JamesLiu
 *
 *【程序10】
 *    题目:一球从100米高度自由落下,每次落地后反跳回原高度的一半;再落下,求它在 第10次落地时,共经过多
 *                 少米?第10次反弹多高?
 */
public class ProgramEx10 {

    public static void main(String[] args) {
        
        double height = 100;
        double h = 100;
        for (int i=1; i<=10; i++) {
            h = 0.5 * h;
            height = height + h;
        }
        System.out.println("一共经过"+height+"米");
        System.out.println("第十次反弹"+h+"米");
    }

}


--------------------编程问答-------------------- 【程序1】
 *     题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一
 *           对兔子,假如兔子都不死,问每个月的兔子总数为多少?
 *         1.程序分析: 兔子的规律为数列1,1,2,3,5,8,13,21....
--------------------编程问答-------------------- --------------------编程问答-------------------- 第五题很明显有错误,首先返回的char类型,不能是“”表示,再有结果不对 --------------------编程问答-------------------- 多谢楼主了,真的很感谢啊 --------------------编程问答-------------------- --------------------编程问答-------------------- --------------------编程问答-------------------- 以前的时候做过,不过现在都基本没做这些了。感觉好亲切啊 --------------------编程问答-------------------- java邮件系统自己写的感觉还不错 下载地址:http://download.csdn.net/source/3220522

另外还可以在这里先看看运行效果:http://blog.csdn.net/afgasdg/archive/2011/04/24/6359702.aspx --------------------编程问答-------------------- 第六题好像不对哦!
--------------------编程问答-------------------- 第六题不知这样改对不对?
import java.util.Scanner;

public class ProgramEx6 {

    public static void main(String[] args)  {


                  System.out.print("请输入两个整数");
        Scanner scan = new Scanner(System.in);
        int m = scan.nextInt();
        int n = scan.nextInt();

        int a, b;
        if (m<n) {
            b = m;
            m = n;
            n = b;
        }
        int c = m*n;
        while(n!=0) {
               a = m%n;
               m = n;
               n = a;


           }        

    System.out.println("它们的最大公约数是:"+m);
       System.out.println("它们的最小公倍数是:"+c/m);
    }
} --------------------编程问答-------------------- 没必要跟着答案走,答案只是参考 --------------------编程问答-------------------- --------------------编程问答-------------------- 第5題 我運行了 貌似不對吧 我改了下可以運行了:

import java.io.*;

public class ProgramEx5 {

    public static void main(String[] args) throws Exception {
        String  m;
        int d;
        BufferedReader br = new BufferedReader (new InputStreamReader (System.in));
        m = br.readLine();
        d=Integer.parseInt(m);

        char a = 'a';
        char b = 'b';
        char c = 'c';

        char n =(d>=90)?a:((d>60)?b:c);
        System.out.println(n); 
        
    } --------------------编程问答-------------------- 第五题答案中明显的错误,字符怎么能用""来呢,再强调一下,答案只是参考,思考还是靠自己的,否则从这些题目无法提高 --------------------编程问答-------------------- --------------------编程问答-------------------- 为什么我自己写的答案然后发帖分享就没有人回复呢? --------------------编程问答-------------------- 楼主很有耐心嘛 --------------------编程问答-------------------- --------------------编程问答-------------------- 第十题答案是错误的。。。 --------------------编程问答-------------------- --------------------编程问答--------------------
引用 91 楼 sowhatwhocare 的回复:
第十题答案是错误的。。。

知道错了就行了,问题是要自己思考 --------------------编程问答-------------------- --------------------编程问答-------------------- 分享了   樓主 --------------------编程问答-------------------- 感谢楼主,很好 --------------------编程问答-------------------- --------------------编程问答-------------------- --------------------编程问答-------------------- 十四题 ,加个验证日期合法性更好:

public boolean isLeapYear(int x){
  if(x%400==0)
  return true;
  else if((x%4==0)&&(x%100!=0))
  return true;
  else return false;
  }
  public boolean isLegal(int y,int m,int d){
  y=(y>0?y:0);
  m=(m>0&&m<13?m:0);
  if(isLeapYear(y)&&m==2&&(d>29||d<0))
  d=0;
  else if(!isLeapYear(y)&m==2&&(d>28||d<0))
  d=0;
  else if((m==1||m==3||m==5||m==7||m==8||m==10||m==12)&&(d>31||d<0))
  d=0;
  else if((m==4||m==6|m==9||m==11)&&(d>30||d<0))
  d=0;
  return (y*m*d!=0);
  }
--------------------编程问答-------------------- 不错 很有帮助 嘿嘿
补充:Java ,  Java SE
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,