1.求解圆柱体的体积
//求解圆柱体的体积
import java.util.Scanner;
class Circle
{
private double radius;
public Circle(double radius) {this.radius = radius;}
public double getRadius() {
【return radius】 (2分);
}
public void setRadius(double radius) {
【this.radius = radius】(2分);
}
public double getArea() {return
【Math.PI * radius * radius】(2分) ;
}
}
class Cylinder 【extends】(2分) Circle
{
double height =100;
public Cylinder(double radius,double height) {super(radius); this.height = height ;}
public double getVolumn() {
return getArea() * height;
}
}
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double height = sc.nextDouble();
double radius = sc.nextDouble();
Cylinder obj = new Cylinder(radius, height);
System.out.printf("Cylinder obj Volumn is %.2f",【obj.getVolumn()】(2分) );
}
}
2.这是程序填空题模板。题目要求写在这里。
有一张足够大的纸,厚0.01 毫米。问将它对折多少次后可以达到珠穆朗玛峰的高度(8848.43米)。
class FoldCount {
public int getCount(double h) {
int n =0 ;
while(h<8848.43) {
【h = h * 2】(2分);
【n++】(2分);
}
【return n】(2分);
}
}
public class Main {
public static void main(String[] args) {
FoldCount obj;
obj = 【new FoldCount()】(2分);
System.out.println(“count=” +【obj.getCount(0.00001)】(2分)) ;
}
}
}
3.
public class Main {
public static void main(String[] args) {
// Prompt the user to enter a password
java.util.Scanner input = new java.util.Scanner(System.in);
//System.out.print("Enter a string for password: ");
String s = input.nextLine();
if (【isValidPassword(s)】(3分)) {
System.out.println("Valid password");
}
else {
System.out.println("Invalid password");
}
}
/** Check if a string is a valid password */
public static boolean isValidPassword(String s) {
// Only letters and digits?
for (int i = 0; i < s.length(); i++) {
if (【!Character.isLetter(s.charAt(i))】(3分)) &&
!Character.isDigit(s.charAt(i)))
return false;
}
// Check length
if (【s.length()】(2分) < 8)
return false;
// Count the number of digits
int count = 0;
for (int i = 0; i < s.length(); i++) {
if (【Character.isDigit(s.charAt(i))】(2分))
count++;
}
if (count >= 2)
return true;
else
return false;
}
}
4.这是程序填空题模板。题目要求写在这里。例如:本题目要求打印“Hello World!”。
相同的数组。如果两个数组list1和list2的内容相同,那么就说它们是相同的。使用下面的程序可以判断两个数组是否相同,请填空补全程序。
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int size1 = input.nextInt();
int[] list1 = new int[size1];
// Enter values for list1
for (int i = 0; i < list1.length; i++)
list1[i] = input.nextInt();
int size2 = input.nextInt();
int[] list2 = new int[size2];
// Enter values for list2
for (int i = 0; i < list2.length; i++)
list2[i] = input.nextInt();
input.close();
if (【equals(list1, list2)】(4分)) {
System.out.println("Two lists are identical");
} else {
System.out.println("Two lists are not identical");
}
}
public static boolean equals(int[] list1, int[] list2) {
if (【list1.length != list2.length】(3分))
return false;
Arrays.sort(list1);
【Arrays.sort(list2)】(3分);
for (int i = 0; i < list1.length; i++)
if (list1[i] != list2[i])
return false;
return true;
}
}