谁有2008,2009,2010年计算机JAVA笔试试题和答案呢?

2008年计算机Java笔试试题及答案

2009年计算机考试Java笔试试题和答案

2010年计算机考试Java笔试试题和答案

下面地址也许有帮助:

java笔试题大全带答案

谁有2006年4月java考试试题和答案很着急

自己在baidu上搜啊!!!

JAVA基础题目

---------------------------------PlayGame.java-----------------------

package play;

import javax.swing.JOptionPane;

public class PlayGame {

private int people[] ;//被困在岛上的一群人,数组。

private int number;//数到哪个数字的倍数就退出

//构造函数,初始化岛上的人数与要数到就让人退出的那个数。

public PlayGame(int numberOfPeople ,int number){

people = new int[numberOfPeople];

this.number = number;

//初始时将所有的数组值设为0,在玩的时候,如果谁退出了游戏,其值就为1.

for(int i = 0 ; i 1){//一直到只剩一个人时,结果循环

//for循环:每次都从头扫一遍整个数组,如果数组中某个元素值不为0(即已经退出了游戏了)就跳过这个无素。

for(int index = 0 ; index < people.length; index ++){

if(people[index]!= 0)//如果数组中某个元素值不为0(即已经退出了游戏了)

index ++;//就跳过这个无素,本质是count没有增1(count在下面增1)

if(count%number == 0){//判断数到的数是不是那个不幸的数的倍数(求余为0, 即整除)。

people[index]=1;//设当前值为1,即那个人退出游戏了。

System.out.printf("当数到%d时,编号为%d的人退出!\n",count,(index+1));//输出信息

countOfPeople --;//玩游戏的人少了一个。

count++;//用以数数。

for(int i = 0 ; i < people.length ; i ++){

if( people[i]==0)

resultID = i+1;//用以返回剩下的那个人的编号,则下标加1(因为数组的下标从0开始)。

//System.out.println("剩下的人为"+ (i+1));

return resultID;//返回得到竹排的人的编号。

public static void main(String[] args) {

try{

String s = JOptionPane.showInputDialog(null, "有多少人参加游戏?");

int n = Integer.parseInt(s);

String s2 = JOptionPane.showInputDialog(null, "数到哪个数字就退出?");

int tmp = Integer.parseInt(s2);

PlayGame p = new PlayGame(n,tmp);

int i = p.play();

JOptionPane.showMessageDialog(null, "得到了竹排的人的编号为:" + i);

}catch(NumberFormatException e){}

到参考地点看看吧,《java谁得到竹排》,那里写得更清楚!并且有运行结果。条理更清晰!约瑟夫问题package my;

import javax.swing.JOptionPane;

public class Test75 {

public static void main(String[] args) {

String s = JOptionPane.showInputDialog(null, "请输入认数:");

int n = Integer.parseInt(s);

String s2 = JOptionPane.showInputDialog(null, "请输入数到几的倍数退出:");

int tmp = Integer.parseInt(s2);

play(n,tmp);

private static void play(int num,int tmp) {

int people = num;// 总人数

int[] person = new int[people];

int count, flag, n, m;

for (n = 0; n < people; n++)

person[n] = n + 1;

count = 0;

flag = 0;

m = 0;

while (count < n - 1) {// 这里想剩下几个人就n减几,按你的要求留1个就减了1

if (person[flag] != 0)

m++;

if (m == tmp) {

person[flag] = 0;

count++;

m = 0;

flag++;

if (flag == n)

flag = 0;

System.out.print("剩下的人是:");

for (flag = 0; flag < n; flag++) {

if (person[flag] != 0) {

System.out.print(person[flag] + " ");

java笔试题大全带答案

java 初学者题目

第一题:

(输入每个值的时候都按回车,这个值中夹杂"stop"列入停止范围)

具体程序如下:

import java.util.Scanner;

public class WhenStopOthers1 {

public static void main(String[] args) {

// TODO Auto-generated method stub

Scanner input = new Scanner(System.in);

System.out.println("请输入:");

String str = input.next();

while (!str.equals("stop")) {

System.out.println("请继续输入,直到输入stop为止:");

str = input.next();

System.out.println("输入结束.");

/** *********************我是分隔线******************* **/

第二题:

(对已经赋值的一维数组进行逆序输出)

程序如下:

public class BackOut {

public static void main(String[] args) {

String[] s = {"!","了","我","出","输","序","逆","就","样","这"};

for(int i = s.length - 1; i >= 0 ; i--){

System.out.print(s[i]);

if(i == 0){

System.out.println();