亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

java中%1$s什么意思啊?

java中%1$s什么意思啊?

UYOU 2019-07-27 15:15:19
import java.awt.*;import java.awt.event.*;import javax.swing.*;public class Example extends JFrame {static Example frm=new Example();static JTextField txf=new JTextField();static TextArea txa=new TextArea("",8,14,TextArea.SCROLLBARS_VERTICAL_ONLY);static JTextArea txa1=new JTextArea();public static void main(String[] args) {Button btn=new Button("抽取");Button btn1=new Button("退出");frm.setTitle(" ");frm.setSize(600,400);frm.setLayout(null);frm.setBackground(Color.gray);frm.setResizable(false);btn.setBounds(500,250,50,30);btn1.setBounds(500,320,50,30);txf.setBounds(20,50,200,30);txa.setBounds(20,100,200,250);txa1.setBounds(240,50,200,300);txa1.setEditable(false);txa.setEditable(false);txa.setBackground(Color.white);txf.addKeyListener(new Ky());btn.addActionListener(new Act());frm.add(btn);frm.add(btn1);frm.add(txf);frm.add(txa);frm.add(txa1);frm.setVisible(true);}static class Ky implements KeyListener{public void keyPressed(KeyEvent a){if(a.getKeyChar()!='\n')return;String name=txf.getText();if(name.isEmpty())return;txa.append(name+"\n");txa.selectAll();}public void keyReleased(KeyEvent e) { }public void keyTyped(KeyEvent e) {}}static class Act implements ActionListener{public void actionPerformed(ActionEvent a){String perstring=txa.getText();String[] personnelArray=perstring.split("\n");int index=(int)(Math.random()*personnelArray.length);String formatArg="本次抽取觀眾人員:\n\t%1$s\n成為本次觀眾抽獎的大獎得主。"+"\n\n我們將為%1$s頒發:\n\t過期的酸牛奶二十箱。";String info=String.format(formatArg,personnelArray[index]);txa1.setText(info);}}}
查看完整描述

2 回答

?
慕村225694

TA貢獻1880條經驗 獲得超4個贊

被格式化的參數索引%1$s和%2$s分別表示第一位和第二位占位符,$s表示是字符串



查看完整回答
反對 回復 2019-07-28
  • 2 回答
  • 0 關注
  • 766 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號