问答题
本题程序将字符串sir中的字符a用$符号代替,然后将字符串中第一个$字符前的听有字符去掉,并打印输出最后的str字符串。请将下述程序补充完整(注意:不得改动程序的结构,不得增行或删行)。
public class basic
public static void main(String[] args)
String str = "Iamagoodboy,andwhataboutyou";
str =______;
int pos =______;
str =______;
System.out.println (str);
【参考答案】
str.replace(’a’,’$’)。
str.indexOf("$")。
str.substring(pos)。
点击查看答案
<上一题
目录
下一题>
热门
试题
问答题
本题程序的功能是主窗口有一个按钮、一个文本域和一个复选框,初始时窗口的大小是不能调整的,勾选复选框后,窗口大小就可以进行调整,如果取消勾选复选框,则窗口的大小又不能调整,单击按钮可以关闭程序。请将下述程序补充完整(注意:不得改动程序的结构,不得增行或删行)。 import java.awt.*; import java.awt.event.*; class MyFrame extends Frame______ Checkbox box; TextArea text; Button button; MyFrame(String s) super (s); box = new Checkbox( 设置窗口是否可调整大小 ); text = new TextArea(12,12); button = new Button( 关闭窗口 ); button.addActionListener(this); box.addItemListener(this); setBounds(100,100,200,300); setVisible(true); add(text,BorderLayout.CENTER); add(box,BorderLayout.SOUTH); add(button,BorderLayout.NORTH); ______; validate (); public void itemStateChanged(ItemEvent e) if (box.getState() == true) setResizable(true); else setResizable(false); public void actionPerformed(ActionEvent e) dispose(); class simple public static void main(String args[]) new MyFrame( simple );
点击查看答案
问答题
本题程序是一个Applet应用程序,功能是计算前n个自然数的和,程序中用进度条来表示计算的进程。页面中有两个文本框、两个按钮和一个进度条,在第一个文本框中输入要计算的自然数的个数,单击“开始”按钮则开始进行计算,进度条同步显示计算完成的情况。程序中存在若干错误,请找出并改正(注意:不得改动程序的结构,不得增行或删行)。 import javax.swing.*; import javax.swing.border.*; import java.awt.*; import java.awt.event.*; public class advance extends Japplet Container container = null; JButton startButton,stopButton; JTextField inputTextField,outputTextField; JProgressBar pBar = null; Timer timer = null; static int sum = 0; static int counter = 0; public void init() container = this.getContentPane(); container.setLayout(new GridLayout(3,1)); Box hboxl = Box.createHorizontalBox(); container.add(hboxl); hboxl.add(Box.createHorizontalGlue()); JLabel labell = new JLabel( 前 ,JLabeI.LEFT); labell.setFont(new Font( Dialog ,Font.PLAIN,15)); hboxl.add(labell); inputTextField = new JTextField( 100 ,4); hboxl.add(inputTextField); JLabel label2 = new JLabel( 个自然数和是 ,JLabel.LEFT); label2.setFont(new Font( Dialog ,Font.PLAIN,15)); hboxl.add(label2); outputTextField = new JTextField(10); hboxl.add(outputTextField); hboxl.add(Box.createHorizontalGlue()); Box hbox2 = Box.createHorizontalBox(); container.add(hbox2); startButton : new JButton( 开始 ); startButton.addActionListener(new ButtonListener()); hbox2.add(Box.createHorizontalGlue()); hbox2.add(startButton); hbox2.add(Box.createHorizontalGlue()); stopButton = new JButton( 结束 ); stopButton.addActionListener(new ButtonListener() ; hbox2.add(Box.createHorizontalGlue()); hbox2.add(stopButton); hbox2.add(Box.createHorizontalGlue()); pBar = new JProgressBar(); pBar.setStringPainted(true); Border border = BorderFactory.createLineBorder(Color.red,2); pBar.setBorder(border); pBar.setBackground(Color.white); pBar.setForeground(Color.blue); pBar.setMinimum(0); pBar.setMaximum(Integer.parseInt(inputTextField.getText())); container.add(pBar); timer = new Timer(0,TimerListener()); class TimerListener implements ActionListener public void actionPerformed(ActionEvent e) if (Integer.parseInt (inputTextField.getText ()) > 0) counter ++; sum = sum+counter; pBar.setValue (counter); outputTextField,setText (Integer.toString (sum)); else outputTextField,setText ( 0 ); if (counter >= Integer.parseInt(inputTextField.getText ())) timer,stop (); class ButtonListener implements ActionListener public void actionPerformed(ActionEvent e) JButton button = e.getSource(); if (button.getText () == 开始 ) outputTextField,setText ( ); if (inputTextField.getText() != ) pBar.setMaximum (Integer.parseInt (inputTextField.getText ()) ); sum = 0 ; counter = 0; timer.begin (); else if (button.getText () == 结束 ) timer,stop (); outputTextField,setText ( ); sum = 0; counter = 0; pBar.setValue(0);
点击查看答案
相关试题
本题程序是一个Applet应用程序,功能是计算...
本题程序的功能是主窗口有一个按钮、一个文...