java程序设计复习题_java程序设计复习大全(100题及答案).doc

java程序设计复习大全(100题及答案)

Java程序设计总复习题

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

// Programme Name LeapYear.java

public class LeapYear{

public static void main(String args[]){

int year=2010;

if(args.length!=0)

year=Integer.parseInt(args[0]);

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

System.out.println(year+" 年是闰年。");

else

System.out.println(year+" 年不是闰年。");

}

}//if-else语句

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

// programme name ForTest.java

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;

}

System.out.println(“1!+2!+3!+……+10!= ”+sum);

}

}

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

使用冒泡排序(数组)

public class BubbleSort {

public static void main(String[] args) {

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

BubbleSort sorter=new BubbleSort();

sorter.sort(array);

}

//冒泡排序

public void sort(int[] array){

for(int i=1;i

for(int j=0;j

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

int temp=array[j];

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

array[j+1]=temp;

}

}

showArray(array);

}

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

public void showArray(int[] array){

for(int i=0;i

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

}

System.out.println();

}

}

本文来自微传网:

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

import java.util.Scanner;

public class Register {

String name;

String password;

String newPassword;

///

public void nameExe(){

Scanner input=new Scanner(System.in);

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

System.out.print("用户名:");

name=input.next();

System.out.print("密码:");

password=input.next();

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

newPassword=input.next();

while(name.length()<3||(password.equals(newPassword)==false)

||(password.length()<6)){

if(name.length()<3){

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

}

if((password.equals(newPassword)==false)||password.length()<6){

System.out.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值