欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Java作业大全

程序员文章站 2024-03-25 18:16:52
...


Java作业答案大全(持续更新ing)

试题(1)

Java作业大全


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)

Java作业大全

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)

Java作业大全


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。

Java作业大全

Java作业大全


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)

Java作业大全



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)

Java作业大全


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)

Java作业大全


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)

Java作业大全


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)

相关标签: 给兄弟们爽