Java作业大全
程序员文章站
2024-03-25 18:16:52
...
Java作业答案大全(持续更新ing)
试题(1)
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double futureInvestmentValue,investmentAmount,monthlyInterestRate,numOfYears;
investmentAmount = sc.nextDouble();
monthlyInterestRate = sc.nextDouble() / (100 * 12);
numOfYears = sc.nextDouble();
double temp1 = 1 + monthlyInterestRate;
double temp2 = numOfYears*12;
futureInvestmentValue = investmentAmount * Math.pow(temp1 ,temp2);
futureInvestmentValue = (int)(futureInvestmentValue * 100) / 100.0;
System.out.println(futureInvestmentValue);
}
}
试题(2)
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double x , y;
x = sc.nextDouble();
y = sc.nextDouble();
x = Math.abs(x);
y = Math.abs(y);
x = (int)(x * 10) / 10.0;
y = (int)(y * 10) / 10.0;
if((x < 5 || x == 5 )&&( y <2.5 || y == 2.5) ) {
System.out.println("Point ("+ x + ", " + y + ") is in the rectangle");
}else {
System.out.println("Point ("+ x + ", " + y + ") is not in the rectangle");
}
}
}
试题(3)
import java.util.Scanner;
public class LockerQue {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
int stuNum = sc.nextInt();
boolean[] lockers = new boolean[stuNum];
for (int j = 1; j <= stuNum; j++) {
for (int i = j - 1; i < stuNum; i += j) {
lockers[i] = !lockers[i];
}
}
for (int i = 0; i < stuNum; i++) {
if(lockers[i]) {
System.out.println("Locker " + (i + 1) + " is open");
}
}
}
}
试题(4)
这题做了9.90/10.0,做到10.0的dl务必私聊教我www。
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
long cardId = sc.nextLong();
long c1 = cardId / 10;
int sum1 = 0 , sum2 = 0;
long temp = 0;
while(c1 > 0) {
temp = 2*(c1 % 10);
if(temp >= 10) {
temp = temp%10 + temp/10;
}
sum1 += temp;
c1 /= 100;
}
c1 = cardId;
while(c1 > 0) {
temp = c1 % 10;
sum2 += temp;
c1 /= 100;
}
int sum = sum1 + sum2;
if(sum % 10 == 0) {
System.out.println(cardId + " is valid");
}else {
System.out.println(cardId + " is invalid");
}
}
}
试题(5)
public class Bod {
private int age;
private String name;
public Bod(String name , int age) {
this.age = age;
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void growOlder(int nYear) {
this.age += nYear;
}
public static void main(String[] args) {
Bod bod = new Bod("James", 23);
System.out.println(bod.getName() + " " + bod.getAge());
bod.growOlder(13);
System.out.println(bod.getName() + " " + bod.getAge());
}
}
试题(6)
public class Product {
private String code;
private String decription;
private double price;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getDecription() {
return decription;
}
public void setDecription(String decription) {
this.decription = decription;
}
public double getPrice() {
return price;
}
public void setPrice(double price) {
this.price = price;
}
public static void main(String[] args) {
Product p = new Product();
p.setCode("PP20201011");
p.setDecription("good");
p.setPrice(199.98);
System.out.println(p.getCode() + " " + p.getDecription()+ " " + p.getPrice());
}
}
试题(7)
public class Box {
private double length = 3.0;
private static double width = 4.0;
private static double height = 5.0;
public Box() {
}
public Box(double length, double width, double height) {
this.length = length;
this.width = width;
this.height = height;
}
public double getLength() {
return length;
}
public void setLength(double length) {
this.length = length;
}
public static double getWidth() {
return width;
}
public static void setWidth(double width) {
Box.width = width;
}
public static double getHeight() {
return height;
}
public static void setHeight(double height) {
Box.height = height;
}
public double getVolume() {
double volume = (int)(length * width * height * 10) / 10.0;
return volume;
}
public static void main(String[] args) {
Box b = new Box();
System.out.println(b.getLength()+" "+getWidth()+" "+getHeight());
System.out.println(b.getVolume());
}
}
试题(8)
public class Rectangle {
private double length ;
private double width ;
public double getLength() {
return length;
}
public void setLength(double length) {
this.length = length;
}
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
public double getArea() {
double area = (int)(length * width * 10) / 10.0;
return area;
}
public double getPerimeter() {
double perimeter = (int)(2*(length + width) *10) / 10.0;
return perimeter;
}
public static void main(String[] args) {
Rectangle r = new Rectangle();
r.setLength(5.0);
r.setWidth(6.0);
System.out.println(r.getLength()+" "+r.getWidth());
System.out.println(r.getArea()+ " "+ r.getPerimeter());
}
}
试题(9)
上一篇: 哔哩哔哩视频弹幕爬取
下一篇: 2015年华科834复试笔试题
推荐阅读
-
java的字节流、File、异常 File异常
-
Java实现爬取哔哩哔哩视频信息程序
-
java java异常
-
Java实现给图片添加水印 博客分类: Util 水印
-
运行JAVA后微软拼音弹出框锁定窗口的解决办法 微软拼音3.0锁定窗口
-
Java之BigDecimal 博客分类: Java javaBigDecimalArithmeticException
-
Java程序员面试题之一 博客分类: 面试题 面试题面向对象封装类异常运行时异常
-
java开发过程中所有会出现的异常与解决的办法 博客分类: Eclipse web异常
-
异常链 博客分类: java ArithmeticException异常链
-
Java Exception | 异常 博客分类: Java Foundation JavaException异常