一个JAVA程序,希望高手可以给出源代码,我交作业用,不会做,非常感谢
请各位程序设计的高手们,请用java编程一下,非常感谢!!!!!!!!!!
这个用一个循环链表解决,代码如下,结果已验证正确,注释没时间写了,自己慢慢领会吧,我是大学生,也是个编程爱好者,有兴趣加QQ:568883776.希望能帮到你,对了,要记得给我分哈!!!(^o^)
class Node
{
int color;//0代表绿色1代表红色
Node next,brfore;
public Node(int n)
{
this.color=n;
}
}
class Chain//循环链表
{
Node head;
public void init_chain()
{
this.head=new Node(0);
Node p=head;
for(int i=1;i<=14;i++)
{
p.next=new Node(0);
p.next.brfore=p;
p=p.next;
}
p.next=head;
this.head.brfore=p;
}
}
public class Try
{
public static void main(String[] args)
{
int i,j;
Chain chain=new Chain();
chain.init_chain();
Node p=new Node(1);
p.next=chain.head.next;
chain.head.next.brfore=p;
p.brfore=chain.head;
chain.head.next=p;
Node pos=p;
for(i=1;i<=14;i++)
{
for(j=1;j<=13;j++)
pos=pos.brfore;
Node temp=new Node(1);
temp.next=pos.next;
pos.next.brfore=temp;
temp.brfore=pos;
pos.next=temp;
pos=temp;
}
for(j=1;j<=12;j++)
pos=pos.brfore;
for(i=1;i<=30;i++)
{
if(pos.color==0) System.out.print("绿");
else System.out.print("红");
pos=pos.next;
}
System.out.println();
}
}
结果:
绿绿绿绿绿红红红红绿绿红红绿红绿绿红绿红绿红红绿红红绿绿红红
上面的字串,第一个是开始位置,注意要头尾相接哈。
简单java编程!非常感谢!
public class Teacher{
private String name;
private int age;
private int salary;
public void setName(String name){this.name = name;}
public String getName(){return this.name;}
public void setAge(int age){this.age = age;}
public int getAge(){return this.age;}
public void setSalary(int salary){this.salary = salary;}
public int getSalary(){return this.salary;}
}
public class TeacherTest{
public static void main(String[] args){
Teacher[] ts = new Teacher[5];
for(int i =0; i<4; i++){
Teacher t = new Teacher();
t.setName(i+"");
t.setAge(i);
t.setSalary(i);
ts[i] = t;
}
for(int i =0; i<ts.length-1; i++){
if(ts[i].getSalary()>ts[i+1]){
Teacher t = null;
t = ts[i+1];
ts[i+1] = ts[i];
ts[i] = t;
}
}
System.out.print("最高"+ts[length-1].getName()+"钱"+ts[length-1].getSalary()+"年龄"+ts[length-1].getAge());
}
}
简单java 编程!非常感谢!
package com.lingdus.test;
import java.io.Serializable;
public class Student implements Serializable {
private String name;
private int age;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
Student() {}
Student(String name){}
Student(int age){}
Student(String name, int age){}
}
// 第二题,我在另外一个问题已经回答你了。
java小程序编写,请高手帮帮忙,小弟非常感谢
public class Employee {
private int id;//工号
private String name;//姓名
static int wid=0;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Employee(int id, String name) {//两个参数的构造函数
this.id = id; //因为题目中说明需要自动生成ID,所以这边的ID也可以和其他的构造函数一样,但是这样就失去了双参数构造函数的意义了
this.name = name;
}
public Employee() {//没有参数的构造函数
this.id=wid++;
this.name="默认";
}
public Employee(String name) {//只含有一个参数的构造函数
this.name = name;
this.id=wid++;
}
public static void main(String[] args) {
Employee e1 = new Employee();
System.out.println("该员工的工号是:"+e1.getId()+" 该员工的姓名是:"+e1.getName());
e1.setName("aaa");
System.out.println(" 经过修改 该员工的工号是:"+e1.getId()+" 该员工的姓名是:"+e1.getName());
Employee e2 = new Employee("bbbb");
System.out.println("该员工的工号是:"+e2.getId()+" 该员工的姓名是:"+e2.getName());
}
}
因为我认为题目中双参数构造函数的时候,单单指定一个工号而不输入姓名是不合理的,所以没有写这种情况
仅供参考,我觉得编这种练习题,还是自己练练比较好