栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

东北大呲花题目

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

东北大呲花题目

PTA家电题目
interface ComputeWeight {
    double computeWeight();
}

class Television implements ComputeWeight{

    @Override
    public double computeWeight() {
        return 16.6;
    }
}


class AirConditioner implements ComputeWeight{

    @Override
    public double computeWeight() {
        return 40.0;
    }
}

class WashMachine implements ComputeWeight{
    @Override
    public double computeWeight() {
        return 60.0;
    }
}

class Truck {


    private ComputeWeight[] goods;

    public Truck(ComputeWeight[] goods) {
        this.goods = goods;
    }

    public double getTotalWeight() {
        double weight=0.0;
        for (int i = 0; i < goods.length; i++) {
            weight = weight + goods[i].computeWeight();
        }
        return weight;
    }
}
身份证排序
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int count=Integer.valueOf(sc.nextLine());
        String s[]=new String[count];
        for (int i=0;id2.getTime()){
                                temp=s[i];
                                s[i]=s[i+1];
                                s[i+1]=temp;
                            }
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                    }
                }
                for (int i=0;id2.getTime()){
                                temp=s[i];
                                s[i]=s[i+1];
                                s[i+1]=temp;
                            }
                        } catch (ParseException e) {
                            e.printStackTrace();
                        }
                    }
                }
                for (int i=0;i 
重复数据输出yes或no的问题 
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner in=new Scanner(System.in);
        int a[]=new int[10005];//开辟数组去存储输入的数字
        int i=0,sign;//sign是是否出现重复数字的标识变量
        while(in.hasNext())//判断输入是否结束
        {
            a[i]=in.nextInt();
            i++;
        }
        sign=0;
        for(int f=0;f 
统计指定字母开头的单词数量 
import java.util.Scanner;



public class TestChar {
	public static void main(String[] args) {
		char words;
		String str;
		Scanner sc = new Scanner(System.in);
		words = sc.next().charAt(0);
		str = sc.nextLine();
		
		int count = 0;
		String[] strArray = str.split(" ");//把字符串通过" "(空格)拆分为字符串数组
		for (int i = 0; i < strArray.length; i++) {
			if(strArray[i].charAt(0) == words)   //if(strArray.startswitch(String.valueof(words)))
			{
				count++;
			}
		}
		System.out.println(count);

	}

}

设计一个矩形类Rectangle
class Rectangle {
    public double width=1;
    public double height=1;
    public Rectangle(){
    }
    public Rectangle(double width,double height){
        this.width=width;
        this.height=height;
    }
    public double getArea(){
        return width*height;
    }
    public  double getPerimeter(){
        return 2*(width+height);
    }
    
    
}
根据派生类写出基类
 public void say() {
        System.out.println("I'm a person! My name is " + this.name + ".");
    }

    public People(String id, String name) {
        this.id=id;
        this.name=name;

    }

    public People() {

    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
设计Worker类及其子类
class Worker {
    private double Rate;
   public  String name;
   public double salaried;
    public Worker(String name, double salaried) {
        this.name=name;
        this.salaried=salaried;
    }



    public void pay(int time){
        System.out.println("Not Implemented");
    }
}

class HourlyWorker extends Worker {

    public HourlyWorker(String name, double salaried) {
        super(name, salaried);
    }


    public void pay(int time){
        if (time>40){
            System.out.println((time-40)*2*salaried+40*salaried);
        }else {
            System.out.println(salaried*time);
        }

    }


    public void setRate(int i) {
        this.salaried=i;
        
    }
}
class SalariedWorker extends Worker {
    public SalariedWorker(String name, double salaried) {
        super(name, salaried);
    }

    public  void pay(){
        System.out.println("580.0");
    }
    public  void pay(int time){
        System.out.println("580.0");
    }

}
求圆面积自定义异常类
class Circle{
    double r;
    public  Circle(double r){
        this.r=r;
    }

    double area() throws CircleException {
        if(this.r<0){
            throw new CircleException(this.r);
        }
        return 3.14*r*r;
    }
}
class CircleException extends Exception{
    double r;
    public CircleException(double r)
    {
        super();
        this.r=r;
    }
    void print(){
        System.out.println("圆半径为"+this.r+"不合理");
    }

}

成绩录入时的及格与不及格人数统计
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int count=sc.nextInt();
        int pass=0;
        for (int i=0;i100){
                System.out.println(grade+"invalid!");
            }else if (grade>=60){
                pass++;
            }
        }
        System.out.println(pass);
        System.out.println(count-pass);
 
    }
}
 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/858119.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号