一道Java 编程题 帮忙做一下
public class Person {
private static String name;
private static String sex;
private static int age;
Person(String name, int age) {
this.name = name;
this.age = age;
}
public void print() {
System.out.print("名字:" + name + " 性别:" + sex + " 年龄:" + age + " ");
}
}
public class Student extends Person {
private static String school;
private static String department;
private static String studentno;
Student(String name, int age, String school, String department,
String studentno) {
super(name, age);
this.school = school;
this.department = department;
this.studentno = studentno;
}
public void print() {
super.print();
System.out.println("学校是:" + school + " 系是:" + department + " 学号是:"
+ studentno);
}
}
public classTest{
public static void main(String[] args){
ArrayList list=new ArrayList();
list.add(new Loan());
list.add(new Date());
list.add(new String("我要找个好工作!");
list.add(new JFrame("这个对象不熟悉,不过大概创建都是这样子的");
list.add(new Circle());
loop(list);//调用方法
}
//循环遍历集合的方法
public void loop(List list){
for(Object obj:list){
System.out.println(obj.toString());
}
}
}
//自定义Circle类
class Circle{
public int radius;//半径
public String toString(){
return "我是一个"+radius+"的圆";
}
}
//这可是哥们一个字母一个字母的敲的,认真看看吧
double length;
double width;
double height;
public Box(double length, double width, double height) {
this.length = length;
this.width= width;
this.height= height;
this.sex = sex;
}
public Box() {
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
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 getMj() {
return this.getLength()*this.getWidth();
}
public double getTj() {
return this.getLength()*this.getWidth()*this.getHeight();
}
public String toString() {
return "长:"+this.getLength()+"宽:"+this.getWidth()+"高:"+this.getHeight()+"面积:"+this.getMj()+"体积:"+this.getTj();
}
public static void main(String[] args) {
Box box=new Box(12,23,4);
System.out.println(box.toString())
}
}
这么简单,自己做吧,就当锻炼下!
黄姿哮喘:[答案] public class Max {private int array[] = { 2,5,3,8,6 };public Max(){}public void getMax(){int i;int max = array[0];for (i = 0; i max) {max = array[i];}}System.out.p...
渭城区15161614221: 帮忙做一JAVA编程题.任意输入N个自然数,输出其奇数的和以及偶数的和. - ?
黄姿哮喘: import java.io.*; public class Calcu {public Calcu() {}public static void main(String[] arg){try{BufferedReader in = new BufferedReader(new InputStreamReader(System.in));String[] num_str=in.readLine().split(" ");int sum_even=0,sum_odd=...
渭城区15161614221: 请帮我做个java编程题目: - ?
黄姿哮喘: import java.util.InputMismatchException; import java.util.Scanner; public class Test { public static void main(String[] args) {//输入一个整数放入到变量n中,如果这个整数大于0,那么计算1+2+3+......+(n-1)+n的结果,否则输出"输入的数据有错误"....
渭城区15161614221: 一道JAVA程序设计题,高手帮忙,谢了 - ?
黄姿哮喘: public class TimerTest {public static void main(String[] args) {Time time=new Time(12,00,00);System.out.print(time.toString());}} /*** 根据以下要求编写一个时间类Time,要求:* ①该类有hour、minute、second三个私有整型成员变量(分...
渭城区15161614221: 一道java编程题 - ?
黄姿哮喘: package Demo; import java.util.HashMap; import java.util.Map; import java.util.Scanner; public class Demo9 { /** * 随便输入一段字符串,把出现次数最多的打印出来,如:aabbbbbbbbbcccdffff,就把b打印出来,用java代码实现 */ public static void...
渭城区15161614221: 帮忙做一JAVA编程题目,谢谢,递归方法 - ?
黄姿哮喘: import java.util.*;//引入控制台需要的输入的包 public class 递归 { static int way(int N){ int s=0; if(N>=1)s=N+way(N-1); return s; } public static void main(String[]arg){ Scanner input=new Scanner(System.in);//从控制台输入 int NUM=input.nextInt(...
渭城区15161614221: 一道java 编程练习题,谁帮帮忙啊? - ?
黄姿哮喘: public static void main(String[] args) { int rand = 1000; //随机数最大值 int[][] array = new int[10][10]; //长度为10*10的二维数组 Set<Integer> set = new HashSet<Integer>(); while(true){ if(set.size()==100) break; set.add((int)(Math.random()*rand)); } ...
渭城区15161614221: 一道简单的JAVA题————急!!!!!!! 新手学JAVA 感谢帮忙!!!! - ?
黄姿哮喘: 从控制台读入10个数字,你看下吧!import java.util.Scanner;public class Test{ public static void main(String[] args) { Sc...
渭城区15161614221: java一道题 请用java基础语句帮忙编写下 - ?
黄姿哮喘: import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.util.Iterator; import java.util.Map; import java.util.Set; import java.util.TreeMap; public class Engto { public static void main(String[] args) throws ...
渭城区15161614221: 一道初级水平的JAVA编程题,谁来帮我 - ?
黄姿哮喘: public class Car{ private String number; public void ShowNumber() { System.out.println(number); } public void SetNumber(String number) { this.number = number; } pu...