赞
踩
- 1
-
- import java.util.Scanner;
- public class Main{
- public static void main(String[] args){
- Rectangle R1 = new Rectangle(40,4);
- Rectangle R2 = new Rectangle(35.9,3.5);
- System.out.println(R1.getArea() + "\n" + R2.getArea());
- System.out.println(R1.getPerimeter() + "\n" + R2.getPerimeter());
- }
- }
-
- class Rectangle{
- double width = 1;
- double height = 1;
- Rectangle() {
- }
-
- Rectangle(double h, double w){
- height = h;
- width = w;
- }
-
- double getArea(){
- return width*height;
- }
-
- double getPerimeter(){
- return 2*(width+height);
- }
-
- }
-
- 2
-
- import java.util.Scanner;
- public class Main {
- public static void main(String[] args) {
- Stock obj = new Stock("ORCL","Oracle Corporation");
- obj.previousClosingPrice = 34.5;
- obj.currentPrice = 34.35;
- System.out.println(obj.getChangePercent());
- }
- }
-
- class Stock{
- String symbol;
- String name;
- double previousClosingPrice = 0.0;
- double currentPrice = 0.0;
-
- public Stock(String sym, String na){
- symbol = sym;
- name = na;
- }
-
- public String getChangePercent(){
- return Math.abs(((currentPrice-previousClosingPrice)/previousClosingPrice))*100+"%";
- }
- }
-
- 3
-
- import java.util.Scanner;
- import java.util.Date;
-
- public class Main{
-
- public static void main(String[] args){
- long num = 10000;
- Date date = new Date(num);
- System.out.println(date.toString());
-
- date.setTime(num*10);
- System.out.println(date.toString());
-
- date.setTime(num*100);
- System.out.println(date.toString());
-
- date.setTime(num*1000);
- System.out.println(date.toString());
-
- date.setTime(num*num);
- System.out.println(date.toString());
-
- date.setTime(num*num*10);
- System.out.println(date.toString());
-
- date.setTime(num*num*100);
- System.out.println(date.toString());
-
- date.setTime(num*num*1000);
- System.out.println(date.toString());
- }
- }
-
- 4
-
- import java.util.Scanner;
- import java.util.Random;
-
- public class Main{
-
- public static void main(String[] args){
- Random random = new Random(1000);
- for(int i = 0; i < 50; ++i){
- System.out.print(random.nextInt(100) + " ");
- if(i%10 == 0)
- System.out.println();
- }
- }
- }
-
- 5
-
- import java.util.Scanner;
- import java.util.GregorianCalendar;
- //我很纳闷为什么输出结果是一样的
- public class Main{
-
- public static void main(String[] args){
- GregorianCalendar calendar = new GregorianCalendar();
- System.out.println(calendar.YEAR + ":" + calendar.MONTH + ":" + calendar.DAY_OF_MONTH);
-
- calendar.setTimeInMillis(1234567898765L);
- System.out.println(calendar.YEAR + ":" + calendar.MONTH + ":" + calendar.DAY_OF_MONTH);
- }
- }
-
- 6
-
- import java.util.Scann
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。