6 5 1 2 結(jié)果才是6;男排 女排 男序號(hào) 女序號(hào)

創(chuàng)新互聯(lián)建站-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比祁門網(wǎng)站開發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫(kù),直接使用。一站式祁門網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋祁門地區(qū)。費(fèi)用合理售后完善,十載實(shí)體公司更值得信賴。
。。。。。。。。。。。。。。。。。。。。。。。。。
package net;
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("請(qǐng)輸入男排人數(shù):");
int boyArray = sc.nextInt();
System.out.println("請(qǐng)輸入女排人數(shù):");
int girlArray = sc.nextInt();
System.out.println("請(qǐng)輸入男生序號(hào):");
int boy = sc.nextInt();
System.out.println("請(qǐng)輸入女生序號(hào):");
int girl = sc.nextInt();
int count=0;
for(int i=1;i=boyArray*girlArray;i++){
if(iboyArray||igirlArray){
if(i==boyi==girl){
count=i;
System.out.println("該對(duì)男女第一次牽手跳舞的序號(hào)是a:"+i);
break;
}
}
else if((i%boyArray==boy)(i%girlArray==girl)){
count=i;
System.out.println("該對(duì)男女第一次牽手跳舞的序號(hào)是:"+i);
break;
}
}
if(count==0){
System.out.println("該對(duì)男女不可能一起跳舞!");
}
}
}
代碼如下,可以直接運(yùn)行。
public static void main(String[] args) {
final int M = 6; // number of girls,可改動(dòng)
final int N = 7; // number of boys,可改動(dòng)
int x = 3;// some boy,可改動(dòng)
int y = 5;// some girl,可改動(dòng)
String result = "";// 記錄結(jié)果,即第二個(gè)問(wèn)題
// 初始化,假設(shè)隊(duì)列存放男女生編號(hào),從1開始
QueueInteger boys = new LinkedListInteger();
for (int i = 1; i = N; i++) {
boys.add(i);
}
QueueInteger girls = new LinkedListInteger();
for (int i = 1; i = M; i++) {
girls.add(i);
}
// 跳舞開始
int min = boys.size() girls.size() ? girls.size() : boys.size();
int k = 1;// songs
int count = 2; // 求出兩個(gè)值,可改動(dòng)
while (k 1000) {//為了不死循環(huán),這里假設(shè)最多有999支舞蹈
System.out.println("***This is the " + k + "st dance:");
for (int i = 0; i min; i++) {
// 跳舞,第一個(gè)問(wèn)題:輸出每曲配對(duì)情況
System.out.println("Boy " + boys.peek() + " = Girl "
+ girls.peek());
// 跳過(guò)的排到對(duì)尾
int boy = boys.remove();
boys.add(boy);
int girl = girls.remove();
girls.add(girl);
// 判斷 x和y跳舞了沒(méi)有
if (boy == x girl == y) {
result += k + ",";
count--;
}
}
if (count == 0)
break;
// next dance
k++;
}
// 結(jié)果
if (count == 0)
System.out.println("\n***Boy " + x + " and Girl " + y
+ " dance together in : " + result);//第二個(gè)問(wèn)題的解答,跳了哪幾支舞
else
System.out.println("\n***Boy " + x + " and Girl " + y
+ " have no chance to dance!");//第二個(gè)問(wèn)題的解答,兩人沒(méi)機(jī)會(huì)跳舞
}
/**
假設(shè)在周末舞會(huì)上,男士們(m人)和女士們(n人)進(jìn)入舞廳時(shí),各自排成一隊(duì)。跳舞開始時(shí),依次從男隊(duì)和女隊(duì)的隊(duì)頭上各出一人配成舞伴。若兩隊(duì)初始人數(shù)不相同,則較長(zhǎng)的那一隊(duì)中未配對(duì)者等待下一輪舞曲。現(xiàn)要求寫一算法模擬上述舞伴配對(duì)問(wèn)題。并m和n存在什么條件時(shí),第x個(gè)(1 =x =m)男生才有可能和他心儀的第y個(gè)(1 =x =n)女生跳舞,在第幾首曲子時(shí)?
*/
import java.util.ArrayList;
import java.util.List;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Dance{
private List String boy=new ArrayList String();
private List String girl=new ArrayList String();
public Dance(int m,int n){
init(m,n);
}
public void init(int m,int n){
for(int i=0;i m;i++){
boy.add("man"+i);
}
for(int i=0;i n;i++){
girl.add("girl"+i);
}
}
public int getMin(){
return Math.min(boy.size(),girl.size());
}
public void go(){
String b="man1";
String g="girl2";
int count=0;
int i=0;
boolean bool=true;
while(bool){
if(i%getMin()==0)
System.out.println("第"+(++count)+"次:");
boolean bGirl=girl.get(i%girl.size()).equals(g);
boolean bBoy=boy.get(i%boy.size()).equals(b);
bool=!(bGirlbBoy);
System.out.println((boy.get((i)%boy.size())).toString());
System.out.println((girl.get((i)%girl.size())).toString());
i++;
}
System.out.println(b+"要在"+count+"首歌中才可以和"+g+"一起Dancing");
}
public static void main(String [] args)throws Exception{
int m;
int n;
System.out.println("請(qǐng)輸入男士人數(shù):");
m=input();
System.out.println("請(qǐng)輸入女士人數(shù):");
n=input();
Dance dance=new Dance(m,n);
dance.go();
}
public static int input()throws Exception{
int returnNum=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String line=br.readLine();
while(!line.equalsIgnoreCase("exit")){
try{
returnNum=new Integer(line);
if(returnNum 0) throw new Exception();
break;
}catch(Exception e){
System.out.println("輸入數(shù)據(jù)有誤!請(qǐng)重新輸入,退出請(qǐng)按exit");
line=br.readLine();
}
}
return returnNum;
}
}
import?java.awt.Canvas;
import?java.awt.Color;
import?java.awt.Dimension;
import?java.awt.EventQueue;
import?java.awt.Frame;
import?java.awt.Graphics;
import?java.awt.Graphics2D;
import?java.awt.Image;
import?java.awt.RenderingHints;
import?java.awt.event.KeyEvent;
import?java.awt.event.KeyListener;
import?java.awt.event.WindowAdapter;
import?java.awt.event.WindowEvent;
import?java.awt.image.BufferedImage;
import?java.io.File;
import?java.io.IOException;
import?javax.imageio.ImageIO;
public?class?TestImage?extends?Frame
{
private?static?final?long?serialVersionUID?=?1L;
private?static?boolean?PRESSED?=?false;
private?static?int?pointX?=?0;
private?static?int?pointy?=?200;
private?static?int?RIGHT_GO?=?0;
private?static?int?LEFT_GO?=?0;
private?static?int?DIR?=?0;
private?static?int?ANGLE?=?0;
private?static?int?W?=?50;
private?static?int?H?=?60;
private?_Canvas?canvas?=?null;
public?TestImage?()
{
add?(canvas?=?new?_Canvas?());
setIgnoreRepaint?(true);
requestFocus?();
}
public?class?_Canvas?extends?Canvas?implements?Runnable
{
private?static?final?long?serialVersionUID?=?1L;
private?BufferedImage?bi?=?null;
private?Image?bufferedImage?=?null;
private?Thread?thread?=?null;
private?long?sleepTime?=?10;
public?_Canvas?()
{
try
{
bi?=?ImageIO.read?(new?File?("go.png"));
}
catch?(IOException?e)
{}
setBackground?(Color.BLACK);
requestFocus?();
addKeyListener?(new?KeyListener?()
{
@Override
public?void?keyTyped?(?KeyEvent?e?)
{}
@Override
public?void?keyReleased?(?KeyEvent?e?)
{
RIGHT_GO?=?0;
PRESSED?=?false;
}
@Override
public?void?keyPressed?(?KeyEvent?e?)
{
//?38?40?37?39上下左右
DIR?=?e.getKeyCode?();
PRESSED?=?true;
}
});
}
@Override
public?void?paint?(?Graphics?g?)
{
Graphics2D?g2d?=?(Graphics2D)?g;
g2d.setRenderingHint?(RenderingHints.KEY_INTERPOLATION,?RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2d.drawImage?(rotateImage?(bi.getSubimage?(RIGHT_GO,?LEFT_GO,?W,?H),?ANGLE,?true),?pointX,?pointy,?W,?H,
this);
g2d.dispose?();
}
@Override
public?void?update?(?Graphics?g?)
{
if?(null?==?bufferedImage)
{
bufferedImage?=?createImage?(getWidth?(),?getHeight?());
}
Graphics?bufferedG?=?bufferedImage.getGraphics?();
bufferedG.clearRect?(0,?0,?getWidth?(),?getHeight?());
paint?(bufferedG);
bufferedG.dispose?();
g.drawImage?(bufferedImage,?0,?0,?this);
g.dispose?();
}
public?void?start?()
{
thread?=?new?Thread?(this);
thread.setName?("TestImage");
thread.setPriority?(Thread.MIN_PRIORITY);
thread.start?();
}
public?synchronized?void?stop?()
{
thread?=?null;
notify?();
}
@Override
public?void?run?()
{
Thread?me?=?Thread.currentThread?();
while?(thread?==?me??!isShowing?()?||?getSize?().width?==?0)
{
try
{
Thread.sleep?(555);
}
catch?(InterruptedException?e)
{
return;
}
}
while?(thread?==?me??isShowing?())
{
if?(PRESSED)
{
try
{
if?(DIR?==?39)
{
RIGHT_GO?=?RIGHT_GO?+?50;
LEFT_GO?=?0;
pointX?=?pointX?+?1;
if?(pointX??420)
{
ANGLE?=?90;
pointX--;
pointy--;
W?=?60;
H?=?50;
}
if?(RIGHT_GO??50)
{
RIGHT_GO?=?0;
}
}
else?if?(DIR?==?37)
{
pointX?=?pointX?-?1;
RIGHT_GO?=?RIGHT_GO?+?50;
LEFT_GO?=?60;
if?(pointX??0)
{
ANGLE?=?-90;
pointX++;
pointy--;
W?=?60;
H?=?50;
}
if?(RIGHT_GO??50)
{
RIGHT_GO?=?0;
}
}
else?if?(DIR?==?38)
{
W?=?50;
H?=?60;
pointy?=?150;
ANGLE?=?0;
RIGHT_GO?=?100;
}
else?if?(DIR?==?40)
{
W?=?50;
H?=?60;
ANGLE?=?0;
pointy?=?200;
RIGHT_GO?=?0;
}
Thread.sleep?(sleepTime);
repaint?();
}
catch?(InterruptedException?e)
{
break;
}
}
else
{
RIGHT_GO?=?RIGHT_GO?+?50;
LEFT_GO?=?0;
pointX?=?pointX?+?1;
if?(RIGHT_GO??50)
{
RIGHT_GO?=?0;
}
if?(pointX??500)
{
pointX?=?0;
}
try
{
Thread.sleep?(sleepTime);
repaint?();
}
catch?(InterruptedException?e)
{
break;
}
}
}
thread?=?null;
}
}
/**
?*?旋轉(zhuǎn)圖像為指定角度
?*?
?*?@param?degree
?*?@return
?*/
public?static?BufferedImage?rotateImage?(?final?BufferedImage?image,?final?int?angdeg,?final?boolean?d?)
{
int?w?=?image.getWidth?();
int?h?=?image.getHeight?();
int?type?=?image.getColorModel?().getTransparency?();
BufferedImage?img;
Graphics2D?graphics2d;
(?graphics2d?=?(?img?=?new?BufferedImage?(w,?h,?type)?).createGraphics?()?).setRenderingHint?(
RenderingHints.KEY_INTERPOLATION,?RenderingHints.VALUE_INTERPOLATION_BILINEAR);
graphics2d.rotate?(d???-Math.toRadians?(angdeg)?:?Math.toRadians?(angdeg),?w?/?2,?h?/?2);
graphics2d.drawImage?(image,?0,?0,?null);
graphics2d.dispose?();
return?img;
}
public?static?void?main?(?String[]?args?)
{
EventQueue.invokeLater?(new?Runnable?()
{
@Override
public?void?run?()
{
final?TestImage?ti?=?new?TestImage?();
ti.setSize?(new?Dimension?(500,?300));
ti.setLocationRelativeTo?(null);
ti.addWindowListener?(new?WindowAdapter?()
{
@Override
public?void?windowClosing?(?WindowEvent?e?)
{
System.exit?(0);
}
@Override
public?void?windowDeiconified?(?WindowEvent?e?)
{
ti.canvas.start?();
}
@Override
public?void?windowIconified?(?WindowEvent?e?)
{
ti.canvas.stop?();
}
});
ti.setResizable?(false);
ti.canvas.start?();
ti.setVisible?(true);
}
});
}
}
regedit;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import java.io.*;
public class Regedit extends JFrame {
private JLabel account = new JLabel("賬號(hào)");
private JTextField aText = new JTextField(10);
private JLabel password = new JLabel("密碼");
private JPasswordField pText = new JPasswordField(10);
private JLabel conpass = new JLabel("確認(rèn)密碼");
private JPasswordField cText = new JPasswordField(10);
private JLabel birthday = new JLabel(" 生日");
private JComboBox year = new JComboBox(data(11, 1985));
private JLabel y = new JLabel("年");
private JComboBox month = new JComboBox(data(13, 0));
private JLabel m = new JLabel("月");
private JComboBox day = new JComboBox(data(32, 0));
private JLabel d = new JLabel("日");
private JLabel sex = new JLabel("性別");
private ButtonGroup group = new ButtonGroup();
private JRadioButton man = new JRadioButton("男", false);
private JRadioButton woman = new JRadioButton("女", false);
private JLabel interest = new JLabel(" 興趣");
private JCheckBox read = new JCheckBox("閱讀");
private JCheckBox sing = new JCheckBox("唱歌");
private JCheckBox dance = new JCheckBox("跳舞");
private JLabel remakes = new JLabel(" 備注");
private JTextArea rText = new JTextArea(6, 15);
private JButton button = new JButton("注冊(cè)");
private String name, pass1, pass2, birth = "", intre = "", se, remake;
public static void main(String[] args) {
new Regedit();
}
public Regedit() {
setTitle("Regedit");
JPanel tz = new JPanel(new GridLayout(1, 2));
JPanel tOne = new JPanel(new GridLayout(3, 2));
JPanel tTwo = new JPanel(new FlowLayout(FlowLayout.LEFT));
JPanel tThree = new JPanel(new BorderLayout());
JPanel tFour = new JPanel(new BorderLayout());
JPanel tFive = new JPanel(new GridLayout(3, 1));
JPanel tSix = new JPanel(new GridLayout(1, 2));
JPanel tSeven = new JPanel(new GridLayout(2, 1));
JPanel tEight = new JPanel(new GridLayout(2, 1));
JPanel tNine = new JPanel(new FlowLayout(FlowLayout.LEFT));
JPanel tTen = new JPanel(new GridLayout(1, 2));
setLayout(new GridLayout(1, 2));
tOne.add(account);
tOne.add(aText);
aText.addActionListener(new Textaction(aText));
tOne.add(password);
tOne.add(pText);
pText.addActionListener(new Textaction(pText));
pText.setEchoChar('*');
tOne.add(conpass);
tOne.add(cText);
cText.addActionListener(new Textaction(cText));
cText.setEchoChar('*');
tTwo.add(birthday);
tTwo.add(year);
year.addActionListener(new birthday(year));
tTwo.add(y);
tTwo.add(month);
month.addActionListener(new birthday(month));
tTwo.add(m);
tTwo.add(day);
day.addActionListener(new birthday(day));
tTwo.add(d);
tSix.add(sex);
group.add(man);
man.addActionListener(new sex());
group.add(woman);
woman.addActionListener(new sex());
tSeven.add(man);
tSeven.add(woman);
tSeven.setBorder(BorderFactory.createLineBorder(Color.gray));
tSix.add(tSeven);
tFour.add(interest, BorderLayout.WEST);
tFive.add(read);
read.addActionListener(new interest(read));
tFive.add(sing);
sing.addActionListener(new interest(sing));
tFive.add(dance);
dance.addActionListener(new interest(dance));
tFive.setBorder(BorderFactory.createLineBorder(Color.gray));
tFour.add(tFive);
tNine.add(remakes);
rText.setBorder(BorderFactory.createLineBorder(Color.gray));
tNine.add(rText);
rText.setLineWrap(true);
tNine.add(button);
button.addActionListener(new button());
tz.add(tOne);
tThree.add(tTwo, BorderLayout.NORTH);
tThree.add(tFour);
tz.add(tThree);
tEight.add(tz);
tTen.add(tSix);
tTen.add(tNine);
tEight.add(tTen);
add(tEight);
pack();
setVisible(true);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private Integer[] data(int day, int j) {
Integer[] data = new Integer[day];
data[0] = null;
if (j == 0)
j = 1;
for (int i = 1; i data.length; i++) {
data[i] = j + i - 1;
}
return data;
}
class Textaction implements ActionListener {
private JTextField text;
public Textaction(JTextField JTF) {
text = JTF;
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == aText) {
name = text.getText();
FocusManager.getCurrentManager().focusNextComponent();
}
if (e.getSource() == pText) {
FocusManager.getCurrentManager().focusNextComponent();
pass1 = text.getText();
}
if (e.getSource() == cText) {
pass2 = text.getText();
FocusManager.getCurrentManager().focusNextComponent();
}
}
}
class birthday implements ActionListener {
private JComboBox combo = new JComboBox();
public birthday(JComboBox JCB) {
combo = JCB;
}
public void actionPerformed(ActionEvent e) {
birth += combo.getSelectedItem() + " ";
}
}
class sex implements ActionListener {
public void actionPerformed(ActionEvent e) {
se = e.getActionCommand();
}
}
class interest implements ActionListener {
private JCheckBox check;
public interest(JCheckBox JBC) {
check = JBC;
}
public void actionPerformed(ActionEvent e) {
if (check.isSelected()) {
intre += e.getActionCommand() + " ";
}
}
}
class button implements ActionListener {
public void actionPerformed(ActionEvent e) {
int result = JOptionPane.showConfirmDialog(null, "您確定注冊(cè)嗎?", "請(qǐng)確認(rèn)",
JOptionPane.YES_NO_OPTION);
if (result == JOptionPane.OK_OPTION) {
remake = remakes.getText();
try {
FileWriter out = new FileWriter("D:/Information.txt", true);
out.write(name + " " + pass1 + " " + se + " " + birth + " "
+ intre + " " + remake + "\r\n");
out.close();
} catch (IOException io) {
io.getStackTrace();
}
}
}
}
}
分享文章:跳舞java動(dòng)態(tài)代碼,java動(dòng)態(tài)執(zhí)行代碼
文章位置:http://chinadenli.net/article6/dsgdcig.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作、品牌網(wǎng)站建設(shè)、用戶體驗(yàn)、、全網(wǎng)營(yíng)銷推廣、網(wǎng)站改版
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)
移動(dòng)網(wǎng)站建設(shè)知識(shí)