最新JAVA编程题全集(50题及答案) 2(7)

时间:2025-04-20

}

【程序13】

题目:一个整数,它加上100后是一个完全平方数,再加上168又是一个完全平方数,请问该数是多少?

public class lianxi13 {

public static void main(String[] args) {

for(int x =1; x<100000; x++) {

if(Math.sqrt(x+100) % 1 == 0) {

if(Math.sqrt(x+268) % 1 == 0) {

System.out.println(x + "加100是一个完全平方数,再加168又是一个完全平方数"); }

}

}

}

}

/*按题意循环应该从-100开始(整数包括正整数、负整数、零),这样会多一个满足条件的数-99。

但是我看到大部分人解这道题目时都把题中的“整数”理解成正整数,我也就随大流了。*/

【程序14】

题目:输入某年某月某日,判断这一天是这一年的第几天?

import java.util.*;

public class lianxi14 {

public static void main(String[] args) {

int year, month, day;

int days = 0;

int d = 0;

int e;

input fymd = new input();

do {

e = 0;

System.out.print("输入年:");

year =fymd.input();

System.out.print("输入月:");

month = fymd.input();

System.out.print("输入天:");

day = fymd.input();

if (year < 0 || month < 0 || month > 12 || day < 0 || day > 31) {

System.out.println("输入错误,请重新输入!");

e=1 ;

}

}while( e==1);

for (int i=1; i <month; i++) {

switch (i) {

最新JAVA编程题全集(50题及答案) 2(7).doc 将本文的Word文档下载到电脑

精彩图片

热门精选

大家正在看

× 游客快捷下载通道(下载后可以自由复制和排版)

限时特价:7 元/份 原价:20元

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219