public class shi {
public static void main(String[] args) {
int n = 5 ,a=0,b=0;
for (int i = n; i >= 1; i--) {
if (a != (n - i)) {
System.out.print(" ");
a++;
i = i + 1;
} else if (b != (2 * i - 1)) {
System.out.print("*");
b++;
i = i + 1;
} else if (a == (n - i) && b == (2 * i - 1)) {
System.out.println();
a = 0;
b = 0;
}
}
}
}
--------------------------------------------------------------------------
2
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
public class ks extends Frame implements WindowListener ,KeyListener{
Image m,d,j;
int y =134;
int a=50;
public ks()
{
super("菜单");
setSize(300,300);
setVisible(true);
addWindowListener(this);
m= Toolkit.getDefaultToolkit().getImage("menu.png");
d= Toolkit.getDefaultToolkit().getImage("A.png");
j= Toolkit.getDefaultToolkit().getImage("B.png");
addKeyListener(this);
}
public void paint(Graphics g )
{
g.drawImage(m,0,0,getWidth(),getHeight(),this);
g.drawString("游戏开始",130,150);
g.drawString("游戏结束",130,200);
g.drawImage(d,100,y,20,20,this);
g.drawImage(j,100,y,20,20,this);
}
public static void main(String[] args) {
new ks();
}
/* (非 Javadoc)
* @see java.awt.event.WindowListener#windowOpened(java.awt.event.WindowEvent)
*/
public void windowOpened(WindowEvent e) {
// TODO 自动生成方法存根
}
/* (非 Javadoc)
* @see java.awt.event.WindowListener#windowClosing(java.awt.event.WindowEvent)
*/
public void windowClosing(WindowEvent e) {
// TODO 自动生成方法存根
System.exit(0);
}
/* (非 Javadoc)
* @see java.awt.event.WindowListener#windowClosed(java.awt.event.WindowEvent)
*/
public void windowClosed(WindowEvent e) {
// TODO 自动生成方法存根
}
/* (非 Javadoc)
* @see java.awt.event.WindowListener#windowIconified(java.awt.event.WindowEvent)
*/
public void windowIconified(WindowEvent e) {
// TODO 自动生成方法存根
}
/* (非 Javadoc)
* @see java.awt.event.WindowListener#windowDeiconified(java.awt.event.WindowEvent)
*/
public void windowDeiconified(WindowEvent e) {
// TODO 自动生成方法存根
}
/* (非 Javadoc)
* @see java.awt.event.WindowListener#windowActivated(java.awt.event.WindowEvent)
*/
public void windowActivated(WindowEvent e) {
// TODO 自动生成方法存根
}
/* (非 Javadoc)
* @see java.awt.event.WindowListener#windowDeactivated(java.awt.event.WindowEvent)
*/
public void windowDeactivated(WindowEvent e) {
// TODO 自动生成方法存根
}
/* (非 Javadoc)
* @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent)
*/
public void keyTyped(KeyEvent e) {
// TODO 自动生成方法存根
}
/* (非 Javadoc)
* @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
*/
public void keyPressed(KeyEvent e) {
// TODO 自动生成方法存根
if(e.getKeyCode()==KeyEvent.VK_UP)
{
y=y-a;
repaint();
}
if(e.getKeyCode()==KeyEvent.VK_DOWN)
{
y=y+a;
}
repaint();
}
/* (非 Javadoc)
* @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent)
*/
public void keyReleased(KeyEvent e) {
// TODO 自动生成方法存根
}
}