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.
總結
以上是生活随笔為你收集整理的java程序设计复习题_java程序设计复习大全(100题及答案).doc的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 远程操控电脑如此简单电脑上怎么远程操控
- 下一篇: iOS版小鸡模拟器怎样安装使用