当前位置:首页 > 代码 > 正文

java程序开发大全源代码(java开发实例大全源码)

admin 发布:2022-12-19 15:17 99


本篇文章给大家谈谈java程序开发大全源代码,以及java开发实例大全源码对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。

本文目录一览:

java新手,求完整的源代码

//都是从新手过来的,以下代码供参考

//1.

public class BankAccount {

private static String acctnum;

private static double money;

private static void showAcct() {

System.out.println("账号为: " + acctnum);

}

private static void showMoney() {

System.out.println("余额为: " + money);

}

public BankAccount(String acc, double m) {

this.acctnum = acc;

this.money = m;

}

public static void main(String[] args) {

BankAccount ba = new BankAccount("626600018888", 5000.00);

ba.showAcct();

ba.showMoney();

}

}

//2.

public class Triangle {

private static float a;

private static float b;

private static float c;

public Triangle(float a, float b, float c) {

this.a = a;

this.b = b;

this.c = c;

}

public static boolean judgeTriangle(float a, float b, float c) {

if ((a  Math.abs(b - c)  a  b + c)

 (b  Math.abs(a - c)  b  a + c)

 (c  Math.abs(a - b)  c  a + b))

return true;

else

return false;

}

public float getCircumference() {

return this.a + this.b + this.c;

}

}

//3.

public class TestTriangle {

public static void main(String[] args) {

Triangle t = new Triangle(5.3f,7.8f,9.3f);

if(t.judgeTriangle(5.3f,7.8f,9.3f)){

System.out.print("能够成三角形,周长为: ");

System.out.printf("%9.2f",t.getCircumference());}

else

System.out.println("不能构成三角形");

}

}

Java简易程序 源代码 public class Hello { public stati

你在输出后面加个i就好了,循环到几就输出几

for(i=1;i10;i++)

System.out.println(”Yuanzhen“+i);

}

求java版画图程序的源代码

找到了,很久以前写的一个简单画图,呵呵~当时要求用AWT写,很难受。

package net.miqiang.gui;

import java.awt.BasicStroke;

import java.awt.BorderLayout;

import java.awt.Button;

import java.awt.Color;

import java.awt.Cursor;

import java.awt.Dimension;

import java.awt.Frame;

import java.awt.Graphics;

import java.awt.Graphics2D;

import java.awt.GridLayout;

import java.awt.Label;

import java.awt.Panel;

import java.awt.RenderingHints;

import java.awt.Toolkit;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.MouseAdapter;

import java.awt.event.MouseEvent;

import java.awt.event.MouseListener;

import java.awt.event.MouseMotionListener;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

import java.awt.image.BufferedImage;

/**

* 简单画图板程序

* 好久没用 AWT 了,写起来真别扭,如果用 swing 会很舒服,有空再改写吧。

*

* @author 米强

*

*/

public class TestMain extends Frame {

// 画板

private Palette palette = null;

// 显示当前颜色的面板

private Panel nonceColor = null;

// 画笔粗细

private Label drawWidth = null;

// 画笔端点的装饰

private Label drawCap = null;

// 选取颜色按钮的监听事件类

private ButtonColorAction buttonColorAction = null;

// 鼠标进入按钮后光标样式的监听事件类

private ButtonCursor buttonCursor = null;

// 画笔样式的监听事件

private ButtonStrokeAction buttonStrokeAction = null;

/**

* 构造方法

*

*/

public TestMain() {

// 设置标题栏文字

super("简易画图板");

// 构造一个画图板

palette = new Palette();

Panel pane = new Panel(new GridLayout(2, 1));

// 画笔颜色选择器

Panel paneColor = new Panel(new GridLayout(1, 13));

// 12 个颜色选择按钮

Button [] buttonColor = new Button[12];

Color [] color = {Color.black, Color.blue, Color.cyan, Color.darkGray, Color.gray, Color.green, Color.magenta, Color.orange, Color.pink, Color.red, Color.white, Color.yellow};

// 显示当前颜色的面板

nonceColor = new Panel();

nonceColor.setBackground(Color.black);

paneColor.add(nonceColor);

buttonColorAction = new ButtonColorAction();

buttonCursor = new ButtonCursor();

for(int i = 0; i buttonColor.length; i++){

buttonColor[i] = new Button();

buttonColor[i].setBackground(color[i]);

buttonColor[i].addActionListener(buttonColorAction);

buttonColor[i].addMouseListener(buttonCursor);

paneColor.add(buttonColor[i]);

}

pane.add(paneColor);

// 画笔颜色选择器

Panel paneStroke = new Panel(new GridLayout(1, 13));

// 控制画笔样式

buttonStrokeAction = new ButtonStrokeAction();

Button [] buttonStroke = new Button[11];

buttonStroke[0] = new Button("1");

buttonStroke[1] = new Button("3");

buttonStroke[2] = new Button("5");

buttonStroke[3] = new Button("7");

buttonStroke[4] = new Button("9");

buttonStroke[5] = new Button("11");

buttonStroke[6] = new Button("13");

buttonStroke[7] = new Button("15");

buttonStroke[8] = new Button("17");

buttonStroke[9] = new Button("■");

buttonStroke[10] = new Button("●");

drawWidth = new Label("3", Label.CENTER);

drawCap = new Label("●", Label.CENTER);

drawWidth.setBackground(Color.lightGray);

drawCap.setBackground(Color.lightGray);

paneStroke.add(drawWidth);

for(int i = 0; i buttonStroke.length; i++){

paneStroke.add(buttonStroke[i]);

buttonStroke[i].addMouseListener(buttonCursor);

buttonStroke[i].addActionListener(buttonStrokeAction);

if(i = 8){

buttonStroke[i].setName("width");

}else{

buttonStroke[i].setName("cap");

}

if(i == 8){

paneStroke.add(drawCap);

}

}

pane.add(paneStroke);

// 将画笔颜色选择器添加到窗体中

this.add(pane, BorderLayout.NORTH);

// 将画图板添加到窗体中

this.add(palette);

// 添加窗口监听,点击关闭按钮时退出程序

this.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {

System.exit(0);

}

});

// 设置窗体 ICON 图标

this.setIconImage(Toolkit.getDefaultToolkit().createImage("images/palette.png"));

// 设置窗口的大小

this.setSize(new Dimension(400, 430));

// 设置窗口位置,处于屏幕正中央

this.setLocationRelativeTo(null);

// 显示窗口

this.setVisible(true);

}

/**

* 程序入口

*

* @param args

* 字符串数组参数

*/

public static void main(String[] args) {

new TestMain();

}

/**

* 选取颜色按钮的监听事件类

* @author 米强

*

*/

class ButtonColorAction implements ActionListener {

public void actionPerformed(ActionEvent e) {

Color color_temp = ((Button)e.getSource()).getBackground();

nonceColor.setBackground(color_temp);

palette.setColor(color_temp);

}

}

/**

* 鼠标进入按钮变换光标样式监听事件类

* @author 米强

*

*/

class ButtonCursor extends MouseAdapter {

public void mouseEntered(MouseEvent e) {

((Button)e.getSource()).setCursor(new Cursor(Cursor.HAND_CURSOR));

}

public void mouseExited(MouseEvent e) {

((Button)e.getSource()).setCursor(new Cursor(Cursor.DEFAULT_CURSOR));

}

}

/**

* 设置画笔的监听事件类

* @author 米强

*

*/

class ButtonStrokeAction implements ActionListener {

public void actionPerformed(ActionEvent e) {

Button button_temp = (Button) e.getSource();

String name = button_temp.getName();

if(name.equalsIgnoreCase("width")){

drawWidth.setText(button_temp.getLabel());

palette.setStroke(Float.parseFloat(button_temp.getLabel()));

}else if(name.equalsIgnoreCase("cap")){

drawCap.setText(button_temp.getLabel());

if(button_temp.getLabel().equals("■")){

palette.setStroke(BasicStroke.CAP_SQUARE);

}else if(button_temp.getLabel().equals("●")){

palette.setStroke(BasicStroke.CAP_ROUND);

}

}

}

}

}

/**

* 画板类

*

* @author 米强

*

*/

class Palette extends Panel implements MouseListener, MouseMotionListener {

// 鼠标 X 坐标的位置

private int mouseX = 0;

// 上一次 X 坐标位置

private int oldMouseX = 0;

// 鼠标 Y 坐标的位置

private int mouseY = 0;

// 上一次 Y 坐标位置

private int oldMouseY = 0;

// 画图颜色

private Color color = null;

// 画笔样式

private BasicStroke stroke = null;

// 缓存图形

private BufferedImage image = null;

/**

* 构造一个画板类

*

*/

public Palette() {

this.addMouseListener(this);

this.addMouseMotionListener(this);

// 默认黑色画笔

color = new Color(0, 0, 0);

// 设置默认画笔样式

stroke = new BasicStroke(3.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND);

// 建立 1280 * 1024 的 RGB 缓存图象

image = new BufferedImage(1280, 1024, BufferedImage.TYPE_INT_RGB);

// 设置颜色

image.getGraphics().setColor(Color.white);

// 画背景

image.getGraphics().fillRect(0, 0, 1280, 1024);

}

/**

* 重写 paint 绘图方法

*/

public void paint(Graphics g) {

super.paint(g);

// 转换为 Graphics2D

Graphics2D g2d = (Graphics2D) g;

// 获取缓存图形 Graphics2D

Graphics2D bg = image.createGraphics();

// 图形抗锯齿

bg.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

// 设置绘图颜色

bg.setColor(color);

// 设置画笔样式

bg.setStroke(stroke);

// 画线,从上一个点到新的点

bg.drawLine(oldMouseX, oldMouseY, mouseX, mouseY);

// 将缓存中的图形画到画板上

g2d.drawImage(image, 0, 0, this);

}

/**

* 重写 update 方法

*/

public void update(Graphics g) {

this.paint(g);

}

/**

* @return stroke

*/

public BasicStroke getStroke() {

return stroke;

}

/**

* @param stroke 要设置的 stroke

*/

public void setStroke(BasicStroke stroke) {

this.stroke = stroke;

}

/**

* 设置画笔粗细

* @param width

*/

public void setStroke(float width) {

this.stroke = new BasicStroke(width, stroke.getEndCap(), stroke.getLineJoin());

}

/**

* 设置画笔端点的装饰

* @param cap 参考 java.awt.BasicStroke 类静态字段

*/

public void setStroke(int cap) {

this.stroke = new BasicStroke(stroke.getLineWidth(), cap, stroke.getLineJoin());

}

/**

* @return color

*/

public Color getColor() {

return color;

}

/**

* @param color 要设置的 color

*/

public void setColor(Color color) {

this.color = color;

}

public void mouseClicked(MouseEvent mouseEvent) {

}

/**

* 鼠标按下

*/

public void mousePressed(MouseEvent mouseEvent) {

this.oldMouseX = this.mouseX = mouseEvent.getX();

this.oldMouseY = this.mouseY = mouseEvent.getY();

repaint();

}

public void mouseReleased(MouseEvent mouseEvent) {

}

/**

* 鼠标进入棋盘

*/

public void mouseEntered(MouseEvent mouseEvent) {

this.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));

}

/**

* 鼠标退出棋盘

*/

public void mouseExited(MouseEvent mouseEvent) {

this.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));

}

/**

* 鼠标拖动

*/

public void mouseDragged(MouseEvent mouseEvent) {

this.oldMouseX = this.mouseX;

this.oldMouseY = this.mouseY;

this.mouseX = mouseEvent.getX();

this.mouseY = mouseEvent.getY();

repaint();

}

public void mouseMoved(MouseEvent mouseEvent) {

}

}

求java小程序源代码 在线等 急急急!!!

下面是俄罗斯方块游戏源代码

还没完,这代码太长了,我用我另一个号再粘上

import javax.swing.*;

import javax.swing.JOptionPane;

import javax.swing.border.Border;

import javax.swing.border.EtchedBorder;

import java.awt.*;

import java.awt.event.*;

/**

* 游戏主类,继承自JFrame类,负责游戏的全局控制。

* 内含

* 1, 一个GameCanvas画布类的实例引用,

* 2, 一个保存当前活动块(ErsBlock)实例的引用,

* 3, 一个保存当前控制面板(ControlPanel)实例的引用;*/

public class ErsBlocksGame extends JFrame {

/**

* 每填满一行计多少分*/

public final static int PER_LINE_SCORE = 100;

/**

* 积多少分以后能升级*/

public final static int PER_LEVEL_SCORE = PER_LINE_SCORE * 20;

/**

* 最大级数是10级*/

public final static int MAX_LEVEL = 10;

/**

* 默认级数是5*/

public final static int DEFAULT_LEVEL = 5;

private GameCanvas canvas;

private ErsBlock block;

private boolean playing = false;

private ControlPanel ctrlPanel;

private JMenuBar bar = new JMenuBar();

private JMenu

mGame = new JMenu("游戏设置"),

mControl = new JMenu("游戏控制"),

mWindowStyle = new JMenu("窗口风格");

private JMenuItem

miNewGame = new JMenuItem("新游戏"),

miSetBlockColor = new JMenuItem("设置颜色 ..."),

miSetBackColor = new JMenuItem("设置底色 ..."),

miTurnHarder = new JMenuItem("提升等级"),

miTurnEasier = new JMenuItem("调底等级"),

miExit = new JMenuItem("退出"),

miPlay = new JMenuItem("开始游戏"),

miPause = new JMenuItem("暂停"),

miResume = new JMenuItem("继续");

private JCheckBoxMenuItem

miAsWindows = new JCheckBoxMenuItem("风格1"),

miAsMotif = new JCheckBoxMenuItem("风格2"),

miAsMetal = new JCheckBoxMenuItem("风格3", true);

/**

* 主游戏类的构造函数

* @param title String,窗口标题*/

public ErsBlocksGame(String title) {

super(title);

//this.setTitle("lskdf");

setSize(315, 392);

Dimension scrSize = Toolkit.getDefaultToolkit().getScreenSize();

//获得屏幕的大小

setLocation((scrSize.width - getSize().width) / 2,

(scrSize.height - getSize().height) / 2);

createMenu();

Container container = getContentPane();

container.setLayout(new BorderLayout(6, 0));

canvas = new GameCanvas(20, 12);

ctrlPanel = new ControlPanel(this);

container.add(canvas, BorderLayout.CENTER);

container.add(ctrlPanel, BorderLayout.EAST);

addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent we) {

JOptionPane about=new JOptionPane();

stopGame();

System.exit(0);

}

});

addComponentListener(new ComponentAdapter() {

public void componentResized(ComponentEvent ce) {

canvas.fanning();

}

});

show();

canvas.fanning();

}

// 游戏“复位”

public void reset() {

ctrlPanel.reset();

canvas.reset();

}

/**

* 判断游戏是否还在进行

* @return boolean, true-还在运行,false-已经停止*/

public boolean isPlaying() {

return playing;

}

/**

* 得到当前活动的块

* @return ErsBlock, 当前活动块的引用*/

public ErsBlock getCurBlock() {

return block;

}

/**

* 得到当前画布

* @return GameCanvas, 当前画布的引用 */

public GameCanvas getCanvas() {

return canvas;

}

/**

* 开始游戏*/

public void playGame() {

play();

ctrlPanel.setPlayButtonEnable(false);

miPlay.setEnabled(false);

ctrlPanel.requestFocus();

}

/**

* 游戏暂停*/

public void pauseGame() {

if (block != null) block.pauseMove();

ctrlPanel.setPauseButtonLabel(false);

miPause.setEnabled(false);

miResume.setEnabled(true);

}

/**

* 让暂停中的游戏继续*/

public void resumeGame() {

if (block != null) block.resumeMove();

ctrlPanel.setPauseButtonLabel(true);

miPause.setEnabled(true);

miResume.setEnabled(false);

ctrlPanel.requestFocus();

}

/**

* 用户停止游戏 */

public void stopGame() {

playing = false;

if (block != null) block.stopMove();

miPlay.setEnabled(true);

miPause.setEnabled(true);

miResume.setEnabled(false);

ctrlPanel.setPlayButtonEnable(true);

ctrlPanel.setPauseButtonLabel(true);

}

/**

* 得到当前游戏者设置的游戏难度

* @return int, 游戏难度1-MAX_LEVEL*/

public int getLevel() {

return ctrlPanel.getLevel();

}

/**

* 让用户设置游戏难度

* @param level int, 游戏难度1-MAX_LEVEL*/

public void setLevel(int level) {

if (level 11 level 0) ctrlPanel.setLevel(level);

}

/**

* 得到游戏积分

* @return int, 积分。*/

public int getScore() {

if (canvas != null) return canvas.getScore();

return 0;

}

/**

* 得到自上次升级以来的游戏积分,升级以后,此积分清零

* @return int, 积分。*/

public int getScoreForLevelUpdate() {

if (canvas != null) return canvas.getScoreForLevelUpdate();

return 0;

}

/**

* 当分数累计到一定的数量时,升一次级

* @return boolean, ture-update successufl, false-update fail

*/

public boolean levelUpdate() {

int curLevel = getLevel();

if (curLevel MAX_LEVEL) {

setLevel(curLevel + 1);

canvas.resetScoreForLevelUpdate();

return true;

}

return false;

}

/**

* 游戏开始*/

private void play() {

reset();

playing = true;

Thread thread = new Thread(new Game());

thread.start();

}

/**

* 报告游戏结束了*/

private void reportGameOver() {

JOptionPane.showMessageDialog(this, "游戏结束!");

}

/**

* 建立并设置窗口菜单 */

private void createMenu() {

bar.add(mGame);

bar.add(mControl);

bar.add(mWindowStyle);

mGame.add(miNewGame);

mGame.addSeparator();

mGame.add(miSetBlockColor);

mGame.add(miSetBackColor);

mGame.addSeparator();

mGame.add(miTurnHarder);

mGame.add(miTurnEasier);

mGame.addSeparator();

mGame.add(miExit);

mControl.add(miPlay);

mControl.add(miPause);

mControl.add(miResume);

mWindowStyle.add(miAsWindows);

mWindowStyle.add(miAsMotif);

mWindowStyle.add(miAsMetal);

setJMenuBar(bar);

miPause.setAccelerator(

KeyStroke.getKeyStroke(KeyEvent.VK_P, KeyEvent.CTRL_MASK));

miResume.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0));

miNewGame.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent ae) {

stopGame();

reset();

setLevel(DEFAULT_LEVEL);

}

});

miSetBlockColor.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent ae) {

Color newFrontColor =

JColorChooser.showDialog(ErsBlocksGame.this,

"设置积木颜色", canvas.getBlockColor());

if (newFrontColor != null)

canvas.setBlockColor(newFrontColor);

}

});

miSetBackColor.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent ae) {

Color newBackColor =

JColorChooser.showDialog(ErsBlocksGame.this,

"设置底版颜色", canvas.getBackgroundColor());

if (newBackColor != null)

canvas.setBackgroundColor(newBackColor);

}

});

miTurnHarder.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent ae) {

int curLevel = getLevel();

if (curLevel MAX_LEVEL) setLevel(curLevel + 1);

}

});

miTurnEasier.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent ae) {

int curLevel = getLevel();

if (curLevel 1) setLevel(curLevel - 1);

}

});

miExit.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent ae) {

System.exit(0);

}

});

miPlay.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent ae) {

playGame();

}

});

miPause.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent ae) {

pauseGame();

}

});

miResume.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent ae) {

resumeGame();

}

});

miAsWindows.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent ae) {

String plaf = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";

setWindowStyle(plaf);

canvas.fanning();

ctrlPanel.fanning();

miAsWindows.setState(true);

miAsMetal.setState(false);

miAsMotif.setState(false);

}

});

miAsMotif.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent ae) {

String plaf = "com.sun.java.swing.plaf.motif.MotifLookAndFeel";

setWindowStyle(plaf);

canvas.fanning();

ctrlPanel.fanning();

miAsWindows.setState(false);

miAsMetal.setState(false);

miAsMotif.setState(true);

}

});

miAsMetal.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent ae) {

String plaf = "javax.swing.plaf.metal.MetalLookAndFeel";

setWindowStyle(plaf);

canvas.fanning();

ctrlPanel.fanning();

miAsWindows.setState(false);

miAsMetal.setState(true);

miAsMotif.setState(false);

}

});

}

/**

* 根据字串设置窗口外观

* @param plaf String, 窗口外观的描述

*/

private void setWindowStyle(String plaf) {

try {

UIManager.setLookAndFeel(plaf);

SwingUtilities.updateComponentTreeUI(this);

} catch (Exception e) {

}

}

/**

* 一轮游戏过程,实现了Runnable接口

* 一轮游戏是一个大循环,在这个循环中,每隔100毫秒,

* 检查游戏中的当前块是否已经到底了,如果没有,

* 就继续等待。如果到底了,就看有没有全填满的行,

* 如果有就删除它,并为游戏者加分,同时随机产生一个

* 新的当前块,让它自动下落。

* 当新产生一个块时,先检查画布最顶上的一行是否已经

* 被占了,如果是,可以判断Game Over了。*/

private class Game implements Runnable {

public void run() {

//产生新方快

int col = (int) (Math.random() * (canvas.getCols() - 3)),

style = ErsBlock.STYLES[(int) (Math.random() * 7)][(int) (Math.random() * 4)];

while (playing) {

if (block != null) { //第一次循环时,block为空

if (block.isAlive()) {

try {

Thread.currentThread().sleep(100);

} catch (InterruptedException ie) {

ie.printStackTrace();

}

continue;

}

}

checkFullLine(); //检查是否有全填满的行

if (isGameOver()) { //检查游戏是否应该结束了

miPlay.setEnabled(true);

miPause.setEnabled(true);

miResume.setEnabled(false);

ctrlPanel.setPlayButtonEnable(true);

ctrlPanel.setPauseButtonLabel(true);

reportGameOver();

return;

}

block = new ErsBlock(style, -1, col, getLevel(), canvas);

block.start();

col = (int) (Math.random() * (canvas.getCols() - 3));

style = ErsBlock.STYLES[(int) (Math.random() * 7)][(int) (Math.random() * 4)];

ctrlPanel.setTipStyle(style);

}

}

/**

* 检查画布中是否有全填满的行,如果有就删除之*/

public void checkFullLine() {

for (int i = 0; i canvas.getRows(); i++) {

int row = -1;

boolean fullLineColorBox = true;

for (int j = 0; j canvas.getCols(); j++) {

if (!canvas.getBox(i, j).isColorBox()) {

fullLineColorBox = false;

break;

}

}

if (fullLineColorBox) {

row = i--;

canvas.removeLine(row);

}

}

}

/**

* 根据最顶行是否被占,判断游戏是否已经结束了。

* @return boolean, true-游戏结束了,false-游戏未结束*/

private boolean isGameOver() {

for (int i = 0; i canvas.getCols(); i++) {

ErsBox box = canvas.getBox(0, i);

if (box.isColorBox()) return true;

}

return false;

}

}

JAVA源程序代码

您好,写了一个程序,求素数,并将所有素数存到ArrayList sushu中:

import java.util.ArrayList;

import java.util.zip.Inflater;

public class sushu {

public static void main(String[] args) {

int n=50,b=0;

float a=0,c=0;

ArrayList sushu=new ArrayList();

for(int i=3;i=n;i++){

int state=0;

for(int j=2;j(i/2+1);j++){

a=(float)i/(float)j;

//System.out.println(a);

b=(int)a;

//System.out.println(a-b);

c=a-b;

//System.out.println(c);

if(c==0){state=1;break;}

}

if(state==0)sushu.add(i);

}

System.out.println(sushu);

}

}

输出结果为:[3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]

求一个简单java程序代码,谢谢

public class TestStar {

public static void main(String[] args) {

String star = "*";

for (int i = 0; i 5; i++) {

if (i == 0) {

System.out.print(" " + star);

System.out.println();

}

if (i == 1) {

for (int z = 0; z 4; z++) {

System.out.print(" " + star);

}

System.out.println();

}

if (i == 2) {

System.out.print(" ");

for (int x = 0; x 3; x++) {

System.out.print(" " + star);

}

System.out.println();

}

if (i == 3) {

for (int y = 0; y 2; y++) {

System.out.print(" " + star + " ");

}

}

}

}

}

是好使的 但是我没找到画五角星有什么规律(五角星好象不是正规图形吧?)如果还有什么要求的话 补充问题(如果是用*填充所有的东西 不包括 “ ”的话 我可以重新再给你写一个)

关于java程序开发大全源代码和java开发实例大全源码的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/10043.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载