【Jsp精品源码栏目提醒】:文章导读:在新的一年中,各位网友都进入紧张的学习或是工作阶段。
网学会员整理了Jsp精品源码-java经典小程序 - 其它资料的相关内容供大家参考,祝大家在新的一年里工作和学习顺利!
1,编写程序,判断给定的某个年份是否是闰年。
闰年的判断规则如下: (1)若某个年份能被 4 整除但不能被 100 整除,则是闰年。
(2)若某个年份能被 400 整除,则也是闰年。
import java.util.Scannerclass Bissextile public static void mainString arge System.out.printquot请输入年份quot int year //定义输入的年份名字为“year” Scanner scanner new ScannerSystem.in year scanner.nextInt if yearlt0yeargt3000 System.out.printlnquot年份有误,程序退出!quot System.exit0 if year40ampampyear1000year4000 System.out.printlnyearquot is bissextilequot else System.out.printlnyearquot is not bissextile quot 2,给定一个百分制的分数,输出相应的等级。
90 分以上 A级 8089 B级 7079 C级 6069 D级 60 分以下 E级import java.util.Scannerclass Mark public static void mainString args System.out.printlnquot请输入一个分数quot //定义输入的分数为“mark”,且分数会有小数 double mark Scanner scanner new ScannerSystem.in mark scanner.nextDouble //判断是否有输入错误。
ifmarklt0markgt100 System.out.printlnquot输入有误! quot System.exit0 /判断分数的等级 90 分以上者 A 级, 8089 分者 B 级,7079 分者 C 级, 6069 者 D 级,60 分以下 E 级 / if markgt90 System.out.printlnquotthis mark is grade A quot else if markgt80 System.out.printlnquotthis mark is grade B quot else if markgt70 System.out.printlnquotthis mark is grade C quot else if markgt60 System.out.printlnquotthis mark is grade D quot else System.out.printlnquotthis mark is grade E quot 3,编写程序求 1357……99 的和值。
class he public static void mainString args int number 1 //初始值 1,以后再2 递增上去 int sum 0 for number lt100 number2 sum number System.out.printlnquot1357……99 quot sum 4、利用 for 循环打印 99 表111122 224133 236 339144 248 3412 4416155 2510 3515 4520 5525166 2612 3618 4624 5630 6636177 2714 3721 4728 5735 6742 7749188 2816 3824 4832 5840 6848 7856 8864199 2918 3927 4936 5945 6954 7963 8972 9981//循环嵌套,打印九九乘法表public class NineNine public static void mainStringargs System.out.println for int j1jlt10j forint k1klt10k //老师的做法,判断语句里的 kltj,省去下列的 if 语句。
if kgtj break //此处用 continue 也可以,只是效率低一点 System.out.printquot quotkquotXquotjquotquotjk System.out.println 6、输出所有的水仙花数,把谓水仙花数是指一个数 3 位数,其各各位数字立方和等于其本身, 例如: 153 111 333 555class DafodilNumber public static void mainString args System.out.printlnquot以下是所有的水仙花数quot int number 100 // 由于水仙花数是三位数,故由 100 开始算起 int i j k // i j k 分别为 number 的百位、十位、个位 for int sum numberlt1000 number inumber/100 jnumber-i100/10 knumber-i100-j10 sumiiijjjkkk if sumnumber System.out.printlnnumberquot is a dafodil number quot 7、求 aaaaaa.......aaaaaaaaa 其中 a 为 1 至 9 之中的一个数,项数也要可以指定。
import java.util.Scannerclass Multinomial public static void mainString args int a //定义输入的 a int howMany //定义最后的一项有多少个数字 Scanner scanner new ScannerSystem.in System.out.printlnquot请输入一个 19 的 a 值quot a scanner.nextInt System.out.printlnquot请问要相加多少项?quot howMany scanner.nextInt int sum0 int a1a // 用来保存 a 的初始值 for