
正文
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说明通过了第一次验证
}
if (k==1) {
linePassOne();
}
}
if (yj){ //如果第二个按钮的Y坐标小于空按钮的Y坐标说明第一按钮在第二按钮右边
for (i=y+1;i=j ;i++ ){ //判断第二按钮左侧直到第一按钮中间有没有按钮
if (grid[x][i]!=0){
k=0;
break;
}
else
}
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
}
if (k==1) {
rowPassOne();
}
}
if (xi) {
for (j=x+1;j=i;j++ ) {
if (grid[j][y]!=0) {
k=0;
break;
}
else
}
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说明通过了第二次验证
}
}
if (y0j){ //第一按钮同行空按钮在与第二按钮之间
for (i=y0+1;i=j ;i++){
if (grid[x0][i]!=0) {
k=0;
break;
}
else
}
}
}
public void rowPassOne(){
if (x0i) {
for (j=x0-1;j=i ;j-- ) {
if (grid[j][y0]!=0) {
k=0;
break;
}
else
}
}
if (x0i) {
for (j=x0+1;j=i ;j++ ) {
if (grid[j][y0]!=0) {
k=0;
break;
}
else
}
}
}
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
相关问答
Q1: Java编程(写出程序代码)
写了一个代码,代码如下,可以进行参考
public class sum {
public static void main(String[] args) {
//创建一个Scanner的对象input
Scanner input = new Scanner(System.in);
//提示用户输入数据
System.out.print("请输入一个整数");
//将输入的值赋给n
int n = input.nextInt();
//定义变量接收计算后的和
int sum = 0;
//利用循环进行求和
for (int i = 0; i = n; i++) {
sum+=i;
}
//输出最后的和
System.out.println("从0一直到"+n+"的所有整数的和是:"+sum);
}
}
Q2: java 求个代码
呵呵,开个玩笑。这道题结果在杭州方言看来有点搞笑。楼主可百度一下。
不过出于程序玩玩,可考虑穷举。难点就是再于如何保证1-9只能出现一次。
楼主的除法有点含糊。计算机有整除和小数除法。这里咱考虑整除。
计算机穷举不累,所以不考虑简便运算了。
【代码】
import java.util.HashSet;
import java.util.Set;
public class Hello
{
public static void main(String[] args)
{
for(int a=1;a=9;a++)
{
for(int b=1;b=9;b++)
{
for(int c=1;c=9;c++)
{
for(int d=1;d=9;d++)
{
for(int e=1;e=9;e++)
{
for(int f=1;f=9;f++)
{
for(int g=1;g=9;g++)
{
for(int h=1;h=9;h++)
{
for(int i=1;i=9;i++)
{
//如果全部相等才判断
if(isAToIAllNotSame(a,b,c,d,e,f,g,h,i))
{
if(a+13*b/c+d+12*e-f-11+g*h/i-10==66)
{
System.out.printf("%d+13*%d/%d+%d+12*%d-%d-11+%d*%d/%d-10==66",a,b,c,d,e,f,g,h,i);
System.out.println();
}
}
}
}
}
}
}
}
}
}
}
}
//判断a-i这9个数是不是全部不相等。是的话就返回true否则false
public static Boolean isAToIAllNotSame(int a,int b,int c,int d,int e,int f,int g,int h,int i)
{
SetInteger s=(SetInteger)new HashSet();
s.add(a);
s.add(b);
s.add(c);
s.add(d);
s.add(e);
s.add(f);
s.add(g);
s.add(h);
s.add(i);
if(s.size()==9)
{
return true;
}
else
{
return false;
}
}
}
【运行效果】
1+13*2/3+4+12*6-5-11+7*9/8-10==66
1+13*2/3+4+12*6-5-11+9*7/8-10==66
1+13*2/3+4+12*6-9-11+7*8/5-10==66
1+13*2/3+4+12*6-9-11+8*7/5-10==66
1+13*2/3+7+12*6-5-11+4*9/8-10==66
1+13*2/3+7+12*6-5-11+9*4/8-10==66
1+13*2/3+7+12*6-8-11+4*9/5-10==66
1+13*2/3+7+12*6-8-11+9*4/5-10==66
1+13*2/3+8+12*6-5-11+4*7/9-10==66
1+13*2/3+8+12*6-5-11+7*4/9-10==66
……
有很多。
【判断重复检测】
hashset是一个可以存放不重复元素的集合。所以可以把穷举的把a到i依次放入哈希集合里。
如果里面有9个元素,肯定都不重复。
这么个题目弄的我瓦特都不好了。
Q3: 求java编程的代码
代码如下,望采纳
public class PrintPrime{
public static void main(String args[]){
//设置一个计数变量count,用于统计一行当中已经输出数字的个数
int count = 0;
//写代码时人为判断200为非素数,如果不考虑题目的严格要求的话,可以写成200
for(int i = 100;i=200;i++){
//判断数字是否为素数,若是,则count+1并输出数字
if(PrintPrime.IsPrime(i)){
count++;
System.out.print(i+" ");
}
//如果一行十个已经输出完毕,计数归零,换行
if(count==10){
count=0;
System.out.println();
}
}
}
//判断数字是否为素数
public static boolean IsPrime(int n){
//如果小于等于三,则大于一即为素数
if (n = 3) {
return n 1;
}
//从2循环到数字的开平方,算法优化
for(int i=2;i=Math.sqrt(n);i++){
if(n%i == 0)
return false;
}
return true;
}
}
Q4: Java编程求代码!
Java code
class Vehicle
{
private int speed,size;
//Vehicle constructor
public Vehicle(int speed,int size)
{
this.speed=speed;
this.size=size;
System.out.println("Init speed: "+speed+",Size: "+size);
}
//set speed
public void setSpeed(int speed)
{
this.speed=speed;
System.out.println("Set speed!");
}
//speedUp
public void speedUp()
{
speed*=2;
System.out.println("Speed Up!");
}
//speedDown
public void speedDown()
{
speed-=5;
System.out.println("Speed Down!");
}
//move
public void move()
{
System.out.println("Is moving at speed: "+speed);
}
//main method
public static void main(String[] args)
{
Vehicle vce=new Vehicle(80,200);
vce.move();
vce.setSpeed(120);
vce.move();
vce.speedUp();
vce.move();
vce.speedDown();
vce.move();
}
}
Debug:






