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(); }

}

friendhosting:(优惠55%)大促销,全场VPS降价55%,9个机房,不限流量

每年的7月的最后一个周五是全球性质的“系统管理员日”,据说是为了感谢系统管理员的辛苦工作....friendhosting决定从现在开始一直到9月8日对其全球9个数据中心的VPS进行4.5折(优惠55%)大促销。所有VPS基于KVM虚拟,给100M带宽,不限制流量,允许自定义上传ISO...官方网站:https://friendhosting.net比特币、信用卡、PayPal、支付宝、微信、we...

易探云美国云服务器评测,主机低至33元/月,336元/年

美国服务器哪家平台好?美国服务器无需备案,即开即用,上线快。美国服务器多数带防御,且有时候项目运营的时候,防御能力是用户考虑的重点,特别是网站容易受到攻击的行业。现在有那么多美国一年服务器,哪家的美国云服务器好呢?美国服务器用哪家好?这里推荐易探云,有美国BGP、美国CN2、美国高防、美国GIA等云服务器,线路优化的不错。易探云刚好就是做香港及美国云服务器的主要商家之一,我们来看一下易探云美国云服...

CloudCone:$17.99/年KVM-1GB/50GB/1TB/洛杉矶MC机房

CloudCone在月初发了个邮件,表示上新了一个系列VPS主机,采用SSD缓存磁盘,支持下单购买额外的CPU、内存和硬盘资源,最低年付17.99美元起。CloudCone成立于2017年,提供VPS和独立服务器租用,深耕洛杉矶MC机房,最初提供按小时计费随时退回,给自己弄回一大堆中国不能访问的IP,现在已经取消了随时删除了,不过他的VPS主机价格不贵,支持购买额外IP,还支持购买高防IP。下面列...

java源代码为你推荐
ucosiiucosii操作系统能运行什么软件订单详情在淘宝上买东西,显示订单已发货,但是没有订单详情。可能有几种原因?scanf返回值Scanf()函数的使用实数的定义实数的概念是什么,实数包括0吗?团购网源码谁有功能比较全的团购网的代码?印度it印度IT业与中国IT业的差异?深度剖析!程序员段子有哪些好笑的关于程序员的笑话廖华100个成语典故及其历史人物故事 南京廖华java商城javaweb 网上商城项目适合什么程度的学生做移动硬盘提示格式化我要打开可移动磁盘 为什么显示格式化
免费二级域名 vps安全设置 vps代购 重庆vps租用 免费域名跳转 免费申请域名和空间 火山主机 Dedicated eq2 网盘申请 可外链网盘 天翼云盘 512mb 便宜空间 ncp是什么 最新优惠 hosts文件修改 winserver2008下载 电信测速器在线测网速 火山互联 更多