https://www.myziyuan.com/
- dsadasd
- import java.util.Scanner;import java.util.Random;public class Fangfa{static int sum,sum1=0;public static void main(String [] args){int a=1,b=1,c=1;int k=0,m=1;int money =5000;int zhu =0;boolean flag = true;Random rand = new Random();Scanner input = new Scanner(System.in);while(m==1){while(flag){System.out.println("掷色子开始!");System.out.println("请下注 注:下注金额只能是50的倍数且不能超过1000");zhu=input.nextInt();if(zhu%50==0&&zhu<=1000&&zhu<=money){System.out.println("下注成功");System.out.println("买大请输入数字1,买小输入数字2");k=input.nextInt();a= rand.nextInt(6)+1;b= rand.nextInt(6)+1;c= rand.nextInt(6)+1;sum=a+b+c;if(k==1){if(sum>9){money+=zhu;System.out.println("恭喜您猜对了,骰子点数为"+sum+"结果是大"+"余额为"+money);}else{money-=zhu;System.out.println("很遗憾,骰子点数为"+sum+"结果是小"+"余额为"+money);}}if(k==2){if(sum<=9){money+=zhu;System.out.println("恭喜您猜对了,骰子点数为"+sum+"结果是小"+"余额为"+money);}else{money-=zhu;System.out.println("很遗憾,骰子点数为"+sum+"结果是大"+"余额为"+money);}}flag= false;System.out.println("继续请按1,退出请按任意键"); m=input.nextInt();if(m==1){flag=true;System.out.println("您选择的是继续");}else{flag=false;System.out.println("欢迎您下次再来玩");}}else{System.out.println("下注失败"+"余额为"+money); }}}}}
- 2021-02-24 09:55:01
- bibila
- import java.awt.*;import java.awt.event.*;import javax.swing.*;class mypanel extends Panel implements MouseListener{ int chess[][] = new int[11][11]; boolean Is_Black_True; mypanel() { Is_Black_True = true; for(int i = 0;i < 11;i++) { for(int j = 0;j < 11;j++) { chess[i][j] = 0; } } addMouseListener(this); setBackground(Color.BLUE); setBounds(0, 0, 360, 360); setVisible(true); } public void mousePressed(MouseEvent e) { int x = e.getX(); int y = e.getY(); if(x < 25 || x > 330 + 25 ||y < 25 || y > 330+25) { return; } if(chess[x/30-1][y/30-1] != 0) { return; } if(Is_Black_True == true) { chess[x/30-1][y/30-1] = 1; Is_Black_True = false; repaint(); Justisewiner(); return; } if(Is_Black_True == false) { chess[x/30-1][y/30-1] = 2; Is_Black_True = true; repaint(); Justisewiner(); return; } } void Drawline(Graphics g) { for(int i = 30;i <= 330;i += 30) { for(int j = 30;j <= 330; j+= 30) { g.setColor(Color.WHITE); g.drawLine(i, j, i, 330); } } for(int j = 30;j <= 330;j += 30) { g.setColor(Color.WHITE); g.drawLine(30, j, 330, j); } } void Drawchess(Graphics g) { for(int i = 0;i < 11;i++) { for(int j = 0;j < 11;j++) { if(chess[i][j] == 1) { g.setColor(Color.BLACK); g.fillOval((i + 1) * 30 - 8, (j + 1) * 30 - 8, 16, 16); } if(chess[i][j] == 2) { g.setColor(Color.WHITE); g.fillOval((i + 1) * 30 - 8, (j + 1) * 30 - 8, 16, 16); } } } } void Justisewiner() { int black_count = 0; int white_count = 0; int i = 0; for(i = 0;i < 11;i++)//横向判断 { for(int j = 0;j < 11;j++) { if(chess[i][j] == 1) { black_count++; if(black_count == 5) { JOptionPane.showMessageDialog(this, "黑棋胜利"); Clear_Chess(); return; } } else { black_count = 0; } if(chess[i][j] == 2) { white_count++; if(white_count == 5) { JOptionPane.showMessageDialog(this, "白棋胜利"); Clear_Chess(); return; } } else { white_count = 0; } } } for(i = 0;i < 11;i++)//竖向判断 { for(int j = 0;j < 11;j++) { if(chess[j][i] == 1) { black_count++; if(black_count == 5) { JOptionPane.showMessageDialog(this, "黑棋胜利"); Clear_Chess(); return; } } else { black_count = 0; } if(chess[j][i] == 2) { white_count++; if(white_count == 5) { JOptionPane.showMessageDialog(this, "白棋胜利"); Clear_Chess(); return; } } else { white_count = 0; } } }for(i = 0;i < 7;i++)//左向右斜判断 { for(int j = 0;j < 7;j++) { for(int k = 0;k < 5;k++) { if(chess[i + k][j + k] == 1) { black_count++; if(black_count == 5) { JOptionPane.showMessageDialog(this, "黑棋胜利"); Clear_Chess(); return; } } else { black_count = 0; } if(chess[i + k][j + k] == 2) { white_count++; if(white_count == 5) { JOptionPane.showMessageDialog(this, "白棋胜利"); Clear_Chess(); return; } } else { white_count = 0; } } } } for(i = 4;i < 11;i++)//右向左斜判断 { for(int j = 6;j >= 0;j--) { for(int k = 0;k < 5;k++) { if(chess[i - k][j + k] == 1) { black_count++; if(black_count == 5) { JOptionPane.showMessageDialog(this, "黑棋胜利"); Clear_Chess(); return; } } else { black_count = 0; } if(chess[i - k][j + k] == 2) { white_count++; if(white_count == 5) { JOptionPane.showMessageDialog(this, "白棋胜利"); Clear_Chess(); return; } } else { white_count = 0; } } } } } void Clear_Chess() { for(int i=0;i<11;i++) { for(int j=0;j<11;j++) { chess[i][j]=0; } } repaint(); } public void paint(Graphics g) { Drawline(g); Drawchess(g); } public void mouseExited(MouseEvent e){} public void mouseEntered(MouseEvent e){} public void mouseReleased(MouseEvent e){} public void mouseClicked(MouseEvent e){}}class myframe extends Frame implements WindowListener{ mypanel panel; myframe() { setLayout(null); panel = new mypanel(); add(panel); panel.setBounds(0,23, 360, 360); setTitle("单人版五子棋"); setBounds(200, 200, 360, 383); setVisible(true); addWindowListener(this); } public void windowClosing(WindowEvent e) { System.exit(0); } public void windowDeactivated(WindowEvent e){} public void windowActivated(WindowEvent e){} public void windowOpened(WindowEvent e){} public void windowClosed(WindowEvent e){} public void windowIconified(WindowEvent e){} public void windowDeiconified(WindowEvent e){}}public class mywindow{ public static void main(String argc []) { myframe f = new myframe(); }}
- 2021-02-11 23:52:21
- 金牛科技
- 编写一个java的应用小程序。,public class RandomNum{ public static void main(String[] args) { int num=(int)(Math.random()*800);//取800以内随机数 System.out.println("所取随机数为:"+num); System.out.println("它的百位数字为:"+(num/100));//取百位 System.out.println("它的十位数字为:"+((num-(num/100)*100))/10);//取十位 System.out.println("它的十位数字为:"+(num%10));//取个位 }}
- 2021-02-11 23:52:21