JAVA编程题全集100题及答案

JAVA编程题全集100题及答案


2024年5月21日发(作者:)

Java程序设计总复习题

1、

编写一个Java程序,用if-else语句判断某年份是否为闰年。(分支)

// Programme Name

public class LeapYear{

public static void main(String args[]){

int year=2010;

if(!=0)

year=nt(args[0]);

if((year%4==0 && year%100!=0)||(year%400==0))

n(year+" 年是闰年。");

else

n(year+" 年不是闰年。");

}//if-else语句

2、

编写一个Java程序在屏幕上输出1!+2!+3!+……+10!的和。(循环)

// programme name

public class ForTest {

public static void main( String args[] ) {

int i,j,mul,sum=0;

for(i=1;i<=10;i++) {

mul=1;

for(j=1,j<=i;j++) {

mul=mul*j;

sum=sum+mul;

n(“1!+2!+3!+……+10!= ”+sum);

3、

依次输入10个学生成绩,判断学生(优秀、良好、中等、及格、不及格)并计算人数(switch)

4、

使用冒泡排序(数组)

public class BubbleSort {

public static void main(String[] args) {

int[] array={63,4,24,1,3,5};

BubbleSort sorter=new BubbleSort();

(array);

//冒泡排序

public void sort(int[] array){

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

for(int j=0;j<-1;j++){

if(array[j]>array[j+1]){

int temp=array[j];

array[j]=array[j+1];

array[j+1]=temp;

第 1 页

showArray(array);

//遍历数组,并输出数组的元素。

public void showArray(int[] array){

for(int i=0;i<;i++){

System.

out

.print(array[i]+"t");

System.

out

.println();

5、

实现会员注册,要求用户名长度不小于3,密码长度不小于6,注册时两次输入密码必须相同 (字符

串)

import r;

public class Register {

String name;

String password;

String newPassword;

public void nameExe(){

Scanner input=new Scanner(System.

in

);

System.

out

.println("请输入用户名,密码和验证密码");

name=();

System.

out

.print("密码:");

System.

out

.print("用户名:");

password=();

System.

out

.print("验证密码:");

newPassword=();

while(()<3||((newPassword)==false)

||(()<6)){

if(()<3){

System.

out

.println("用户名不能小于3");

if(((newPassword)==false)||()<6){

System.

out

.println("两次输入密码不一样或密码不能小于6位");

System.

out

.println("n"+"请重新输入");

System.

out

.print("用户名:");

name=();

System.

out

.print("密码:");

password=();

System.

out

.print("验证密码:");

newPassword=();

System.

out

.println("注册成功!");

public class Verify {

public static void main(String[] args) {

Register m1=new Register();

e();

6、

一个景区根据游人的年龄收取不同价格的门票。请编写游人类,根据年龄段决定能够购买的门票价格

并输出,然后写出测试类测试该类(类的基本实现)

public class Tourist {

第 2 页


发布者:admin,转转请注明出处:http://www.yc00.com/web/1716289311a2727122.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信