问两道简单的Java题目!高分求教

来源:百度知道 编辑:UC知道 时间:2024/05/26 09:10:39
1.The greatest common divisor(GCD)of two integers is the largest integer that evenly divids each of the two numbers.White a method gcd that returns the greatest common divisor of two integers.Incorporate the method into an application that reads two values from the user and displays the result.
大意是要求用户输入两个整数,然后计算出它们的最大公约数,然后把结果显示出来给用户看。

2.The use of computers in education is referred to as computer-assisted instruction(CAI).One problem that develops in CAI environments is student fatigue.This problem can be eliminated by varying the computer's responses to hold the student's attention.the various comments are displayed for each correct answer and each incorrect answer as follows:
Responses to a correct answer:

Very good!
Excellent!
Nice work!
keep up the good work!

Responses to an incorrect answer:

No.Please try again.
Wrong.Try once more.
Don

second question:

import java.util.Random;
import java.util.Scanner;

public class rantest
{
public static void main( String args[] )
{
Random randomNumbers = new Random();
Scanner input = new Scanner(System.in);
int a1;
int a2;
int a3;
int a4;
int a5;
int a6;
int k;

System.out.println("Now begin the test!");
System.out.println("This test have 6 questions.Please enter your answer follow the question!");

do
{
System.out.println("Question 1:");
System.out.println("How much is 6 times 7?");
a1 = input.nextInt();

if ( a1 != 42 )
{
k = 1 + randomNumbers.nextInt(4);

switch( k )
{
case 1:
System.out