JAVA编程序找出三队赛手的名单

JAVA编程序找出三队赛手的名单,第1张

public class Bisai {public static void main(String[] args) { char i,j,k; // i是a的对手,j是b的对手,k是c的对手 for ( i = 'x'; i <='z'; i++) { for ( j = 'x'; j <='z'; j++) { if (i!=j) for (k='x';k<='z';k++) if (i!=k && j!=k) if (i!='x' && k!='x' && k!='z') Systemoutprintf("a--%c,b--%c,c--%c",i,j,k); } } }}

import javautilScanner;

public class TestRandom {

 public static void main(String[] args) {

  Scanner s = new Scanner(Systemin);

  int a = 0;

  int b = 0;

  Systemoutprintln("即将上班,请签到");

  Systemoutprintln("请假或签到");

  while (true) {

   String line = snext();

   if("签到"equals(linetrim())){

    a++;

    Systemoutprintln("有" + a +"员工签到");

   }else if("请假"equals(linetrim())){

    b++;

    Systemoutprintln("有" + b +"员工请假");

   }else{

    Systemoutprintln("输入有误,请重新输入");

   }

  }

 }

}

写全部代码是不科学的,给你个提示吧

第一步定义一个数组,用来存放抓到的值

第二步

实例化random

Random

r

=

new

Random();

生成0-4之间的数字

int

n

=

rnextInt(4);

n

=

Mathabs(rnextInt()

%

4);

最后n=n+1;这样就成了1-5之间的数字。

第三步,判断数组里面是否存在这个数字,如果不存在,则放进去,如果存在,就重新生成一次

,直到数组中没有这个数字。

不知道这样讲,明白我的意思不?

再看看别人怎么说的。

找了两组程序

代码一:

import javaawt;

import javaawtevent;

import javaxswing;

class GoodLucky extends JFrame implements ActionListener

{

JTextField tf = new JTextField();

JButton b1 = new JButton("开始");

JButton b2 = new JButton("停止");

boolean sg=false;

public GoodLucky(){

b1setActionCommand("start");

JPanel p = new JPanel();

padd(b1);

padd(b2);

b1addActionListener(this);

b2addActionListener(this);

b2setEnabled(false);

thisgetContentPane()add(tf,"North");

thisgetContentPane()add(p,"South");

thissetDefaultCloseOperation(JFrameEXIT_ON_CLOSE);

thissetSize(300,200);

thissetLocation(300,300);

Cursor cu = new Cursor(CursorHAND_CURSOR);

thissetCursor(cu);

thissetVisible(true);

tfsetText("祝大家鸿运!");

thisgo();

}

public void go()

{

while(true)

{

if(sg==true)

{

String s = " ";

for(int j = 1; j <= 7;j++)

{

int i = (int)(Mathrandom() 9) + 1;

if(i < 10)

{

s = s + " 0" + i;

}

else

{

s = s + " " + i;

}

}

tfsetText(s);

}

try

{

Threadsleep(100);

}

catch(javalangInterruptedException e)

{

eprintStackTrace();

}

}

}

public void actionPerformed(ActionEvent e)

{

String s = egetActionCommand();

if(sequals("start"))

{

sg = true;

b1setEnabled(false);

b2setEnabled(true);

}

else

{

sg= false;

b2setEnabled(false);

b1setEnabled(true);

}

}

public static void main(String[] args)

{

new GoodLucky();

}

}

代码二:

package comsofteemlesson03;

import javaawtBorderLayout;

import javaawtContainer;

import javaawtFont;

import javaawteventMouseAdapter;

import javaawteventMouseEvent;

import javaxswingJButton;

import javaxswingJFrame;

import javaxswingJLabel;

import javaxswingJPanel;

import javaxswingJTextField;

public class LuckyNumberInterface extends JFrame {

JLabel ltitle = new JLabel("欢迎使用本抽奖机", JLabelCENTER);

JLabel linput = new JLabel("幸运号码:");

JTextField input = new JTextField(20);

JButton btnStart = new JButton("开始");

JButton btnStop = new JButton("停止");

JPanel lpanel = new JPanel();

JPanel btnPanel = new JPanel();

public LuckyNumberInterface() {

super("抽奖机");

final LuckyNumber ln = new LuckyNumber(input);

lnstart();

Container container = getContentPane();

lpaneladd(linput);

lpaneladd(input);

btnPaneladd(btnStart);

btnPaneladd(btnStop);

Font font = new Font("宋体", FontBOLD, 16);

ltitlesetFont(font);

containeradd(ltitle, BorderLayoutNORTH);

containeradd(lpanel, BorderLayoutCENTER);

containeradd(btnPanel, BorderLayoutSOUTH);

btnStartaddMouseListener(new MouseAdapter() {

@Override

public void mouseClicked(MouseEvent arg0) {

lnsetFlag(true);

}

});

btnStopaddMouseListener(new MouseAdapter() {

@Override

public void mouseClicked(MouseEvent arg0) {

lnsetFlag(false);

}

});

setDefaultCloseOperation(EXIT_ON_CLOSE);

setSize(400, 120);//设置窗口的显示大小

setLocation(400, 300);//设置窗口显示的位置

setVisible(true);//显示窗口

}

public static void main(String[] args) {

new LuckyNumberInterface();

}

}

package comsofteemlesson03;

import javatextDecimalFormat;

import javautilRandom;

import javaxswingJTextField;

public class LuckyNumber extends Thread {

private String luckyNumber = "";

private boolean flag = false;//开关

private JTextField input;

public LuckyNumber(JTextField input) {

thisinput = input;

}

public void setFlag(boolean flag) {

thisflag = flag;

}

@Override

public void run() {

while (true) {

if (flag) {

generatorLuckyNumber();

}

}

}

public void generatorLuckyNumber() {

String[] firstNumber = { "130", "131", "134", "137", "135", "139",

"150", "151", "155", "158", "159" };

Random rd = new Random();

int number = rdnextInt(10000);

DecimalFormat df = new DecimalFormat("0000");

String lastNumber = dfformat(number);

luckyNumber = firstNumber[rdnextInt(firstNumberlength)] + ""

+ lastNumber;

inputsetText("");

inputsetText(luckyNumber);

}

}

import javautilArrays;

import javautilScanner;

public class Poker {

    private static final int NUM = 1;

    private static int SUM = 52;

    private static final String P = "A,2,3,4,5,6,7,8,9,10,J,Q,K";

    private static String[][] POKER = {

        PreplaceAll("([^,]+)", "黑桃$1")split(","),

        PreplaceAll("([^,]+)", "红桃$1")split(","),

        PreplaceAll("([^,]+)", "梅花$1")split(","),

        PreplaceAll("([^,]+)", "方片$1")split(",")

    };

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System in );

        int count = NUM;

        String[] hand = new String[0];

        Systemoutprintln("随机发 " + count + " 张牌");

        SUM -= count;

        for (int i = 0; i < count; i++) {

            int row = (int)(Mathrandom()  POKERlength);

            int col = (int)(Mathrandom()  POKER[row]length);

            String[] css = new String[handlength + 1];

            Systemarraycopy(hand, 0, css, 0, handlength);

            css[csslength - 1] = POKER[row][col];

            hand = css;

        }

        Systemoutprintln("然后看手里的牌:");

        Systemoutprintln(ArraystoString(hand));

        scannerclose();

    }

}

public class Salary {

/

@param args

/

public static void main(String[] args) {

//用继承,重写方法,都是调用的wages()方法

Person personManager = new Manager();

Systemoutprintln("这个人的工资是:"+personManagerwages());

Person personEngineer = new Engineer();

Systemoutprintln("这个人的工资是:"+personEngineerwages());

Person personWorker = new Worker();

Systemoutprintln("这个人的工资是:"+personWorkerwages());

}

}

//人类

class Person {

public String wages(){

return "";

}

}

//经理类

class Manager extends Person{

public String wages(){

return "5000/月";

}

}

//工程师类

class Engineer extends Person{

public String wages(){

return "3000/月";

}

}

//工人类

class Worker extends Person{

public String wages(){

return "2000/月";

}

}

=’z’;k++)

{ if(i;i++)

for(j=’x’,k是c的对手/,i,j;stdio,j是b的对手,j!=k)

{

if(i;=’z’;i是a的对手,k)h>i&lt!=’x’&&k;j++)

{

if(i;

}

}

}

}

望采纳;tc--%c\!=’x’&&k;

void main()

{

char i;

for(i=’x’,k;tb--%c\k<n”!=k&&j; /=’z’#include<j&lt!=’z’) printf(“order is a--%c\!=j)

for(k=’x’!

以上就是关于JAVA编程序找出三队赛手的名单全部的内容,包括:JAVA编程序找出三队赛手的名单、用Java中做一个签到程序、急~!用JAVA编写出5个人抓阄的程序~等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/9664679.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-30
下一篇 2023-04-30

发表评论

登录后才能评论

评论列表(0条)

保存