java这道题该怎么做
Java参考源代码:
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Test10 extends JFrame implements ActionListener {
protected JList lstLeft = null;
protected JList lstRight = null;
protected JButton btnAdd = null;
protected String[] arr = {"新闻", "娱乐", "体育", "教育"};
public Test10() {
super("列表框");
initComponent();
this.setSize(400, 300);
this.setVisible(true);
this.setLayout(new FlowLayout());
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void initComponent() {
lstLeft = new JList(arr);
lstRight = new JList();
btnAdd = new JButton(">");
this.add(lstLeft);
this.add(btnAdd);
this.add(lstRight);
lstLeft.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
btnAdd.addActionListener(this);
}
public static void main(String[] args) {
new Test10();
}
@Override
public void actionPerformed(ActionEvent e) {
Object[] items = lstLeft.getSelectedValues();
DefaultListModel model = new DefaultListModel();
lstRight.setModel(model);
model.removeAllElements();
for(Object value : items) {
model.addElement(value);
}
}
}
运行测试:
请点击输入图片描述
System.out.println(“请输入第一个操作数:”);
Scanner input2 = new Scanner(System.in).
System.out.println(“请输入第二个操作数:”);
String s1 = input1.next();
String s2 = input2.next();
if(!s1.equals(s2)){
System.out.peintln(“请输入正确数字”);
}
判断怎么判断
Scanner input = new Scanner(System.in).
System.out.println(“请输入:”);
String s = input.next();
if(“5”.equals(s)){
System.out.peintln(“Ok”);
}