填空题

本题定义了一个长度为10的boolean型数组,并给数组元素赋值,要求如果数组元素下标为奇数,则数组元素值为false,否则为true。
public class java1
public static void main(String[] args)
boolean b[]=______;
for(int i=0; i<10; i++)
if(______)
b[i]=false;
else
______;

for(int i=0; i<10; i++)
System. out. print("b["+i+"]="+b[i]+",");

【参考答案】

第1处:new boolean[10]
第2处:i%2!=0
第3处:b[i]=true
热门 试题

填空题
本题的功能是获得系统剪贴板中的内容。窗口中有一个菜单“Edit”和一个文本域,“Edit”中有菜单项“Cut”、“Copy”和“Paste”,在文本域中输入内容,可以通过菜单进行剪切、复制和粘贴操作,如果系统剪贴板为空,又做粘贴操作的话,则设置文本域中背景颜色为红色,并显示错误信息。 import java. awt. * ; import java. io. * ; import java. awt. datatransfer. * ; import java. awt. event. * ; class java3 extends Frame implements ActionListener, ClipboardOwner TextArea textArea=new TextArea(); java3() super( java3 ); addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) System. exit(0); ); MenuBar mb=new MenuBar(); Menu m=new Menu( Edit ); setLayout(new BorderLayout()); add( Center , textArea); m. add( Cut ); m. add( Copy ); m. add( Paste ); mb. add(m); setMenuBar(this); for (int i=0; i<m. getItemCount(); i++) m. item(i). addActionListener(this); setSize(300,300); show(); public void actionPerformed(ActionEvent evt) if ( Paste . equals(evt, getActionCommand())) boolean error=true; Transferable t= getToolkit(). getSystemClipboard(). getContents(this); try if(t ! =null & &. t. isDataFlavorSupported(DataFlavor, stringFlavor)) textArea. setBackground(Color, white); textArea. setForeground(Color, black); textArea. replaceRange( (String) t. getTransferData(DataFlavor. stringFlavor), textArea. getSelectionStart(), textArea. getSelectionEnd()); error=false; catch(UnsupportedFlavorException e) catch(IOException e) if (error) textArea. setBackground(Color, red); textArea. setForeground(Color, white); textArea. repaint(); textArea. setText( ERROR: nEither the clipboard + is empty or the contents is not a string. ); else if ( Copy . equals(evt. getActionCommand ())) setContents(); else if ( Cut . equals (evt. getActionCommand ())) setContents (); textArea. replaceRange( , textArea. getSelectionStart(), textArea. getSelectionEnd()); void setContents() S=textArea. getSelectedText(); StringSelection contents=new StringSelection(s); getToolkit(). getSystemClipboard(). setContents(contents, this); public void lostOwnership (Clipboard clipboard, Transferable contents) System. out. println( lost ownership ); public static void main(String args[]) new java3();