java源代码求一个java程序源码

java源代码  时间:2021-08-05  阅读:()

求一个简单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源代码 import javax.swing.*; import java.awt.*; import java.awt.event.*; public class lianliankan implements ActionListener { JFrame mainFrame; //主面板 Container thisContainer; JPanel centerPanel,southPanel,northPanel; //子面板 JButton diamondsButton[][] = new JButton[6][5];//游戏按钮数组 JButton exitButton,resetButton,newlyButton; //退出,重列,重新开始按钮 JLabel fractionLable=new JLabel("0"); //分数标签 JButton firstButton,secondButton; //分别记录两次被选中的按钮 int grid[][] = new int[8][7];//储存游戏按钮位置 static boolean pressInformation=false; //判断是否有按钮被选中 int x0=0,y0=0,x=0,y=0,fristMsg=0,secondMsg=0,validateLV; //游戏按钮的位置坐标 int i,j,k,n;//消除方法控制 public void init(){ mainFrame=new JFrame("JKJ连连看"); thisContainer = mainFrame.getContentPane(); thisContainer.setLayout(new BorderLayout()); centerPanel=new JPanel(); southPanel=new JPanel(); northPanel=new JPanel(); thisContainer.add(centerPanel,"Center"); thisContainer.add(southPanel,"South"); thisContainer.add(northPanel,"North"); centerPanel.setLayout(new GridLayout(6,5)); for(int cols = 0;cols < 6;cols++){ for(int rows = 0;rows < 5;rows++ ){ diamondsButton[cols][rows]=new JButton(String.valueOf(grid[cols+1][rows+1])); diamondsButton[cols][rows].addActionListener(this); centerPanel.add(diamondsButton[cols][rows]); } } exitButton=new JButton("退出"); exitButton.addActionListener(this); resetButton=new JButton("重列"); resetButton.addActionListener(this); newlyButton=new JButton("再来一局"); newlyButton.addActionListener(this); southPanel.add(exitButton); southPanel.add(resetButton); southPanel.add(newlyButton); fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable.getText()))); northPanel.add(fractionLable); mainFrame.setBounds(280,100,500,450); mainFrame.setVisible(true); } public void randomBuild() { int randoms,cols,rows; for(int twins=1;twins<=15;twins++) { randoms=(int)(Math.random()*25+1); for(int alike=1;alike<=2;alike++) { cols=(int)(Math.random()*6+1); rows=(int)(Math.random()*5+1); while(grid[cols][rows]!=0) { cols=(int)(Math.random()*6+1); rows=(int)(Math.random()*5+1); } this.grid[cols][rows]=randoms; } } } public void fraction(){ fractionLable.setText(String.valueOf(Integer.parseInt(fractionLable.getText())+100)); } public void reload() { int save[] = new int[30]; int n=0,cols,rows; int grid[][]= new int[8][7]; for(int i=0;i<=6;i++) { for(int j=0;j<=5;j++) { if(this.grid[i][j]!=0) { save[n]=this.grid[i][j]; n++; } } } n=n-1; this.grid=grid; while(n>=0) { cols=(int)(Math.random()*6+1); rows=(int)(Math.random()*5+1); while(grid[cols][rows]!=0) { cols=(int)(Math.random()*6+1); rows=(int)(Math.random()*5+1); } this.grid[cols][rows]=save[n]; n--; } mainFrame.setVisible(false); pressInformation=false; //这里一定要将按钮点击信息归为初始 init(); for(int i = 0;i < 6;i++){ for(int j = 0;j < 5;j++ ){ if(grid[i+1][j+1]==0) diamondsButton[i][j].setVisible(false); } } } public void estimateEven(int placeX,int placeY,JButton bz) { if(pressInformation==false) { x=placeX; y=placeY; secondMsg=grid[x][y]; secondButton=bz; pressInformation=true; } else { x0=x; y0=y; fristMsg=secondMsg; firstButton=secondButton; x=placeX; y=placeY; secondMsg=grid[x][y]; secondButton=bz; if(fristMsg==secondMsg && secondButton!=firstButton){ xiao(); } } } public void xiao() { //相同的情况下能不能消去。

仔细分析,不一条条注释 if((x0==x &&(y0==y+1||y0==y-1)) || ((x0==x+1||x0==x-1)&&(y0==y))){ //判断是否相邻 remove(); } else{ for (j=0;j<7;j++ ) { if (grid[x0][j]==0){ //判断第一个按钮同行哪个按钮为空 if (y>j) { //如果第二个按钮的Y坐标大于空按钮的Y坐标说明第一按钮在第二按钮左边 for (i=y-1;i>=j;i-- ){ //判断第二按钮左侧直到第一按钮中间有没有按钮 if (grid[x][i]!=0) { k=0; break; } else{ k=1; } //K=1说明通过了第一次验证 } if (k==1) { linePassOne(); } } if (yx) { for (n=x0;n>=x+1 ;n-- ) { if (grid[n][j]!=0) { k=0; break; } if(grid[n][j]==0 && n==x+1) { remove(); } } } } } for (i=0;i<8;i++ ) { //列 if (grid[i][y0]==0) { if (x>i) { for (j=x-1;j>=i ;j-- ) { if (grid[j][y]!=0) { k=0; break; } else { k=1; } } if (k==1) { rowPassOne(); } } if (xy) { for (n=y0;n>=y+1 ;n--) { if (grid[i][n]!=0) { k=0; break; } if(grid[i][n]==0 && n==y+1) { remove(); } } } } } } } public void linePassOne(){ if (y0>j){ //第一按钮同行空按钮在左边 for (i=y0-1;i>=j ;i-- ){ //判断第一按钮同左侧空按钮之间有没按钮 if (grid[x0][i]!=0) { k=0; break; } else { k=2; } //K=2说明通过了第二次验证 } } if (y0i) { for (j=x0-1;j>=i ;j-- ) { if (grid[j][y0]!=0) { k=0; break; } else { k=2; } } } if (x0num) System.out.println("输入的数大了,输小点的!"); else if (shu求一个java程序源码

.jdom.*; .jdom.input.*; .jdom.output.*; import java.io.*; import java.util.List; /** * <p>Title: 使用JDOM解析XML</p> * <p>Description: 通过使用JDOM接口解析book.xml文件</p> * <p>Copyright: Copyright (c) 2003</p> * <p>Filename: JDOMParsePage.java</p> * @author 杜江 * @version 1.0 */ public class JDOMParsePage { /** *<br>方法说明:构造器,实现XML文件解析 *<br>输入参数: *<br>返回类型: */ public JDOMParsePage() { Document docJDOM; //利用SAX建立Document SAXBuilder bSAX = new SAXBuilder(false); try { //生成document对象 docJDOM = bSAX.build(new File("book.xml")); }catch (JDOMException e) { e.printStackTrace(); return; }

//得到Document的根(节点名:book) Element root = docJDOM.getRootElement(); System.out.println("根节点标记名:" + root.getName());

System.out.println("*****下面遍历XML元素*****"); //获得page元素集合 List list = root.getChildren("page"); //遍历page元素 for (int i=0; i < list.size() ; i++) { //获得page的元素 Element element = (Element)list.get(i); //获得ID属性 String id = element.getAttributeValue("id"); //获得title元素集合 List titleList = element.getChildren("title"); //获得title第一个元素 Element titleElement = (Element)titleList.get(0); //获得title元素的第一个值 String title = titleElement.getText(); //获得file元素集合 List fileList = element.getChildren("file"); //获得file第一个元素 Element fileElement = (Element)fileList.get(0); //获得file元素的第一个值 String file = fileElement.getText();

System.out.println("ID:" + id + " " + "标题:" + title + " " + "文件:" + file); } } /** *<br>方法说明:主方法,启动解析器 *<br>输入参数: *<br>返回类型: */ public static void main(String[] args) { JDOMParsePage myReader = new JDOMParsePage(); }

}

百纵科技,美国独立服务器 E52670*1 32G 50M 200G防御 899元/月

百纵科技:美国高防服务器,洛杉矶C3机房 独家接入zenlayer清洗 带金盾硬防,CPU全系列E52670、E52680v3 DDR4内存 三星固态盘阵列!带宽接入了cn2/bgp线路,速度快,无需备案,非常适合国内外用户群体的外贸、搭建网站等用途。C3机房,双程CN2线路,默认200G高防,3+1(高防IP),不限流量,季付送带宽美国洛杉矶C3机房套餐处理器内存硬盘IP数带宽线路防御价格/月套...

hostkey俄罗斯、荷兰GPU显卡服务器/免费Windows Server

Hostkey.com成立于2007年的荷兰公司,主要运营服务器出租与托管,其次是VPS、域名、域名证书,各种软件授权等。hostkey当前运作荷兰阿姆斯特丹、俄罗斯莫斯科、美国纽约等数据中心。支持Paypal,信用卡,Webmoney,以及支付宝等付款方式。禁止VPN,代理,Tor,网络诈骗,儿童色情,Spam,网络扫描,俄罗斯色情,俄罗斯电影,俄罗斯MP3,俄罗斯Trackers,以及俄罗斯法...

RAKsmart推出7.59美元/月,云服务器产品Cloud Server,KVM架构1核1G内存40G硬盘1M带宽基础配置

近期RAKsmart上线云服务器Cloud Server产品,KVM架构1核1G内存40G硬盘1M带宽基础配置7.59美元/月!RAKsmart云服务器Cloud Server位于美国硅谷机房,下单可选DIY各项配置,VPC网络/经典网络,大陆优化/精品网线路,1-1000Mbps带宽,支持Linux或者Windows操作系统,提供Snap和Backup。RAKsmart机房是一家成立于2012年...

java源代码为你推荐
初始化磁盘台式机新添加的硬盘怎么初始化磁盘rbo在么?那个RBO出招表到底怎么回事 斩舰刀怎么用visio使用教程怎样使用visio画E-R图讯飞tts能配合讯飞语音tts使用的手机阅读器都有哪些小蓝条AU多轨怎么调出每个音轨下面一个小蓝条调整音量数据管理制度简述系统运行管理制度的主要内容程序员段子20、老婆给当程序员的老公打电话:“下班顺路买一斤包子带回来,如果看到卖西瓜的,买一个。”当晚,程序廖华如何构思作文课教案 南京廖华文件系统格式电脑文件系统fat32和NTFS格式是什么 能解释一下吗java商城javaweb 网上商城项目适合什么程度的学生做
godaddy域名注册 enom zpanel 香港vps99idc bandwagonhost 特价空间 国外空间服务商 表格样式 web服务器架设软件 阿里校园 免费cdn 卡巴斯基是免费的吗 万网空间管理 国外的代理服务器 云服务器比较 测试网速命令 江苏徐州移动 wordpress空间 windowssever2008 zencart安装 更多