gajava代码 java 代码大全( 三 )


//}
//}
// 根据染色体打印走法
public String getPath(boolean[] individual) {
int length = individual.length;
int x = 1;
int y = 0;
LinkedListString stack=new LinkedListString();
for (int i = 0; ilength; i++) {
boolean b1 = individual[i];
boolean b2 = individual[++i];
if (b1 == falseb2 == false) {
if (x0labyrinth.map[y][x - 1] == true) {
x--;
if(!stack.isEmpty()stack.peek()=="右")
stack.poll();
else
stack.push("左");
}
} else if (b1 == falseb2 == true) {
if (x + 1widthlabyrinth.map[y][x + 1] == true) {
x++;
if(!stack.isEmpty()stack.peek()=="左")
stack.poll();
else
stack.push("右");
}
} else if (b1 == trueb2 == false) {
if (y0labyrinth.map[y - 1][x] == true) {
y--;
if(!stack.isEmpty()stack.peek()=="下")
stack.poll();
else
stack.push("上");
}
} else if (b1 == trueb2 == true) {
if (y + 1heightlabyrinth.map[y + 1][x] == true) {
y++;
if(!stack.isEmpty()stack.peek()=="上")
stack.poll();
else
stack.push("下");
}
}
}
StringBuilder sb=new StringBuilder(length/4);
IteratorString iter=stack.descendingIterator();
while(iter.hasNext())
sb.append(iter.next());
return sb.toString();
}
}
java编程,题目要求如下 。class Base
{
protected String name;
protected getScore(){return 0;};
}
class Team extends Base
{
private int gf;
private int ga;
private int pts;
private int gd;
public Team(int Gf,int Ga)
{
gf=Gf;
ga=Ga;
gd=gf-ga;
if(gd0)
{
pts=3
}
else if(gd==0)
{
pts=1;
}
else
{
pts=0;
}
}
public int getScore()
{
return pts*10 + gd*5 + gf;
}
}
//大概是这样gajava代码了,看在我大晚上给你写代码gajava代码的份上 , 给我分吧
java画乌龟首先,手动画一个小乌龟,如下:
然后,按照Java绘图基本步骤一步步来 。
swing 编程步骤:
1. 继承JFrame
2. 定义组件
3.创建组件(构造函数)
4.添加组件
5.对窗体设置
6.显示窗体
最终效果如下:
代码如下:
/**
* 功能:画一个乌龟
*/
package com.test1;
import java.awt.*;
import javax.swing.*;
public class MyTortoiseextends JFrame{
MyPanel2 mp = null;
//构造函数
public MyTortoise(){
mp = new MyPanel2();
this.add(mp);
this.setTitle("小乌龟,丑丑哒");
this.setSize(400,300);
this.setVisible(true);
this.setLocation(300,200);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
MyTortoise mtg = new MyTortoise();
}
}
//我的面板 。只有JPanel有画图方法 , JFrame没有,故必须在JFrame中添加JPanel
class MyPanel2 extends JPanel{
//定义一个乌龟
Tortoise t = null;
//构造函数
public MyPanel2(){
t = newTortoise(100,100);
}
//画乌龟
public void drawTortoise(int x, int y, Graphics g){
//1.画脸
g.setColor(Color.green);
g.fillOval(x+60, y, 30, 15);
//2.画左眼
g.setColor(Color.black);
g.fillOval(x+65, y+3, 5, 5);
//3.画右眼
g.fillOval(x+78, y+3, 5, 5);
//4.画脖子
g.setColor(Color.green);
g.fillOval(x+70, y, 10, 42);
//5.画乌龟壳
g.setColor(Color.red);
g.fillOval(x+40, y+40, 70, 100);
//6.画左上脚
g.setColor(Color.green);
g.fillOval(x+15, y+60, 30, 10);
//7.画右上脚
g.fillOval(x+105, y+60, 30, 10);

推荐阅读