java编码代码大全 java程序编码

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;j7;j++ ) {

if (grid[x0][j]==0){ //判断第一个按钮同行哪个按钮为空

if (yj) { //如果第二个按钮的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 (yj){ //如果第二个按钮的Y坐标小于空按钮的Y坐标说明第一按钮在第二按钮右边

for (i=y+1;i=j ;i++ ){ //判断第二按钮左侧直到第一按钮中间有没有按钮

if (grid[x][i]!=0){

k=0;

break;

}

else { k=1; }

}

if (k==1){

linePassOne();

}

}

if (y==j ) {

linePassOne();

}

}

if (k==2) {

if (x0==x) {

remove();

}

if (x0x) {

for (n=x0;n=x-1;n++ ) {

if (grid[n][j]!=0) {

k=0;

break;

}

if(grid[n][j]==0 n==x-1) {

remove();

}

}

}

if (x0x) {

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;i8;i++ ) { //列

if (grid[i][y0]==0) {

if (xi) {

for (j=x-1;j=i ;j-- ) {

if (grid[j][y]!=0) {

k=0;

break;

}

else { k=1; }

}

if (k==1) {

rowPassOne();

}

}

if (xi) {

for (j=x+1;j=i;j++ ) {

if (grid[j][y]!=0) {

k=0;

break;

}

else { k=1; }

}

if (k==1) {

rowPassOne();

}

}

if (x==i) {

rowPassOne();

}

}

if (k==2){

if (y0==y) {

remove();

}

if (y0y) {

for (n=y0;n=y-1 ;n++ ) {

if (grid[i][n]!=0) {

k=0;

break;

}

if(grid[i][n]==0 n==y-1) {

remove();

}

}

}

if (y0y) {

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 (y0j){ //第一按钮同行空按钮在左边

for (i=y0-1;i=j ;i-- ){ //判断第一按钮同左侧空按钮之间有没按钮

if (grid[x0][i]!=0) {

k=0;

break;

}

else { k=2; } //K=2说明通过了第二次验证

}

}

if (y0j){ //第一按钮同行空按钮在与第二按钮之间

for (i=y0+1;i=j ;i++){

if (grid[x0][i]!=0) {

k=0;

break;

}

else{ k=2; }

}

}

}

public void rowPassOne(){

if (x0i) {

for (j=x0-1;j=i ;j-- ) {

if (grid[j][y0]!=0) {

k=0;

break;

}

else { k=2; }

}

}

if (x0i) {

for (j=x0+1;j=i ;j++ ) {

if (grid[j][y0]!=0) {

k=0;

break;

}

else { k=2; }

}

}

}

public void remove(){

firstButton.setVisible(false);

secondButton.setVisible(false);

fraction();

pressInformation=false;

k=0;

grid[x0][y0]=0;

grid[x][y]=0;

}

public void actionPerformed(ActionEvent e) {

if(e.getSource()==newlyButton){

int grid[][] = new int[8][7];

this.grid = grid;

randomBuild();

mainFrame.setVisible(false);

pressInformation=false;

init();

}

if(e.getSource()==exitButton)

System.exit(0);

if(e.getSource()==resetButton)

reload();

for(int cols = 0;cols 6;cols++){

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

if(e.getSource()==diamondsButton[cols][rows])

estimateEven(cols+1,rows+1,diamondsButton[cols][rows]);

}

}

}

public static void main(String[] args) {

lianliankan llk = new lianliankan();

llk.randomBuild();

llk.init();

}

}

//old 998 lines

//new 318 lines

java编码

//我写了个fixString方法可以把s,转化成汉字,然后你在比较,不就可以了

public class t {

public static void main(String[] args) {

String s = "%u4e2d%u56fd";// “中国”的Unicode编码

s = s.replaceAll("%", "\\\\");

System.out.println("s=" + s);// 结果是s=\u4e2d\u56fd

String s2 = "\u4e2d\u56fd";

System.out.println("s2=" + s2);// 结果是“s2=中国”

System.out.println(fixString(s).equals(s2));

}

static String fixString(String s) {

while (true) {

int index = s.indexOf("\\u");

if (index != -1) {

String s1 = s.substring(index, index + 6);

if (s1.matches("\\\\u[0-9A-Fa-f]{4}")) {

char c = (char) Integer.parseInt(s1.replace("\\u", ""), 16);

s = s.substring(0, index) + c + s.substring(index + 6);

}

} else {

break;

}

}

return s;

}

}

求java的具体代码

package org.xmh.demo;

import java.io.BufferedReader;

import java.io.File;

import java.io.FileFilter;

import java.io.FileNotFoundException;

import java.io.FileReader;

import java.io.FileWriter;

import java.io.IOException;

import java.util.ArrayList;

import java.util.List;

import java.util.Scanner;

public class Test {

public static void main(String[] args) {

String str = "";

File file = new File("D://stuinfo.txt");

FileWriter fw = null;

if(!file.exists()){

try {

file.createNewFile();

} catch (IOException e) {

e.printStackTrace();

}

}

try {

fw = new FileWriter(file);

} catch (IOException e2) {

e2.printStackTrace();

}

while(!"over".equals(str)){

Scanner sc = new Scanner(System.in);

System.out.println("请输入学生信息(包括姓名,3门成绩,中间用逗号隔开,如果输入over则结束输入):");

str = sc.next();

if(!"over".equals(str)){

try {

String[] infos = str.split(",");

Student st = new Student(infos[0],

Integer.parseInt(infos[1]),

Integer.parseInt(infos[2]),

Integer.parseInt(infos[3]));

fw.write(st.toString()+"\n");

} catch (Exception e) {

System.out.println(e.getMessage());

System.out.println("输入不正确,请重新输入");

continue;

}

}else{

System.out.println("学生成绩录入结束");

}

}

try {

if(fw!=null){

fw.close();

}

} catch (IOException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

FileReader fr = null;

BufferedReader br = null;

try {

fr = new FileReader(file);

br = new BufferedReader(fr);

String line = null;

while((line=br.readLine())!=null){

System.out.println(line);

}

} catch (IOException e) {

e.printStackTrace();

}finally{

try {

if(br!=null){

br.close();

}

if(fr!=null){

fr.close();

}

} catch (IOException e1) {

// TODO Auto-generated catch block

e1.printStackTrace();

}

}

}

}

class Student{

String name;

int score1;

int score2;

int score3;

public Student(String name,int score1,int score2,int score3){

this.name = name;

this.score1 = score1;

this.score2 = score2;

this.score3 = score3;

}

@Override

public String toString() {

return "student["+name+","+score1+","+score2+","+score3+"]";

}

}

运行结果:

请输入学生信息(包括姓名,3门成绩,中间用逗号隔开,如果输入over则结束输入):

zhangsan,20,20,20

请输入学生信息(包括姓名,3门成绩,中间用逗号隔开,如果输入over则结束输入):

lisi,30,30,30

请输入学生信息(包括姓名,3门成绩,中间用逗号隔开,如果输入over则结束输入):

wangwu,40,40,40

请输入学生信息(包括姓名,3门成绩,中间用逗号隔开,如果输入over则结束输入):

zhaoliu,50,50,50

请输入学生信息(包括姓名,3门成绩,中间用逗号隔开,如果输入over则结束输入):

over

学生成绩录入结束

student[zhangsan,20,20,20]

student[lisi,30,30,30]

student[wangwu,40,40,40]

student[zhaoliu,50,50,50]

望采纳

java编程的代码

1.

public class Gun {          //设置一个枪类

private String name;      //枪名    

private int num;          //子弹的个数

private  int  Id;   //枪的Id

static int count;       

public  Gun(){}

public Gun(String name, int num, int id) {

this.name=name;

this.num=12;

}

public Gun(String name,int num) {

this.name=name;

this.num=num;

this.Id=count++;

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

public int getNum() {

return num;

}

public void setNum(int num) {

this.num = num;

}

public  int getId(){

return Id;

}

public  void setId(int id) {

Id = id;

}

public void fire(){       //枪的发射方法

  

}

@Override

public String toString() {    //覆写toString 

return "Gun [name=" + name + ", num=" + num + ", Id=" + Id + "]";

}  

}

public class Ak_47 extends Gun {

//构造器的重载

public Ak_47(){}       //构造器

public Ak_47(String name,int num){   

super(name,num);

}

public  void fire(){     //发射子弹     ,每次射出3发

   super.setNum(super.getNum()-3);  //得到子弹的数目   

}

public void  clip(){    //装弹夹   每个弹夹30发子弹

   super.setNum(super.getNum()+30);   

}

public String toString(){     //toString的重写

   return "枪名:"+super.getName()+"\t"+"编号:"+super.getId()+"\t"+"子弹数:"+super.getNum();

}

}

public class Usp extends Gun {

public Usp(){}

public Usp(String name,int num){   

super(name,num);

}

 public  void fire(){     //发射子弹 ,每次发射一发

   super.setNum(super.getNum()-1);  //得到子弹的数目   

   }

   public void  clip(){    //装弹夹

   super.setNum(super.getNum()+12);   

   }

   public String toString(){

   return "枪名:"+super.getName()+"\t"+"编号:"+super.getId()+"\t"+"子弹数:"+super.getNum();

   }

}

public class GunTest {

public static void main(String[] args) {

Ak_47 ak=new Ak_47("ak",20);//Ak-47的弹夹可以装30子弹

Ak_47 bk=new Ak_47("us",12);

ak.fire();

bk.fire();

ak.clip();

bk.clip();

System.out.println(ak);

System.out.println(bk);

}

}

可以了

给段最简单的java代码 让我新手看一下

最简单的java代码肯定就是这个了,如下:

public class MyFirstApp

{

public static void main(String[] args)

{

System.out.print("Hello world");

}

}

“hello world”就是应该是所有学java的新手看的第一个代码了。如果是零基础的新手朋友们可以来我们的java实验班试听,有免费的试听课程帮助学习java必备基础知识,有助教老师为零基础的人提供个人学习方案,学习完成后有考评团进行专业测试,帮助测评学员是否适合继续学习java,15天内免费帮助来报名体验实验班的新手快速入门java,更好的学习java!

当前文章:java编码代码大全 java程序编码
网页地址:https://www.cdcxhl.com/article42/hispec.html

成都网站建设公司_创新互联,为您提供定制开发自适应网站定制网站网站排名网站收录网站维护

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都网站建设公司