问答题
简单应用题 请完成下列Java程序:对大写的26个英文字母加密,从键盘输入一个大写字母串,输出这个串加密后的结果。加密操作是将字母变换成倒序的大写字母,如A->Z, B->Y。 注意:请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。 程序运行结果如下: 输入一个大写字母串:ADFSDFFE 加密后的大写字母串:ZWUHWUUV import java.io.*; public class ex12_2{ public static void main (String[] args){ char ch = ’’A’’; String str; System.out.print("输入一个大写字母串:"); try{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); str = in.readLine(); System.out.print("加密后的大写字母串:"); for(int i=0;i
【参考答案】
ch = str.charAt(i) ch = (char )(’Z’ - ch + ’A’)
点击查看答案&解析
<上一题
目录
下一题>
热门
试题
问答题
综合应用题下面是一个Applet程序,其功能是实现一个计数器,每隔0.15秒计数器数值加1,数值动态变化,并且能够控制计数器的暂停和继续。要求通过使用swing的构件建立图形用户界面,主要包括一个文本区域,用于显示计数器结果;两个按钮,一个使计数器暂停,一个使计数器继续工作。请改正程序中的错误(有下划线的语句),使程序能输出正确的结果。注意:不改动程序的结构,不得增行或删行。程序运行结果如下:import javax.swing.*;import java.awt.*; import java.awt.event.*; ** public class ex7_3 extends JApplet {private JTextField jtf = new JTextField(15);private JButton Hold = new JButton( Hold ),resume = new JButton( Resume );private ex7_3th obj7_3th = new ex7_3th();class ex7_3th extends Thread {private int cnt = 0;private boolean bIsHold = false;public ex7_3th() { start(); }public void hold() { bIsHold = true;}public synchronized void fauxResume() {bIsHold = false;wait();}public void run() {while (true) {try {sleep(150);synchronized(this) {while(bIsHold)notify();}} catch(InterruptedException ie) {System.err.println( Interrupted );}jtf.setText(cnt);}}}public void init() {Container cp = getContentPane();cp.setLayout(new FlowLayout());cp.add(jtf);Hold.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent ae) {obj7_3th.hold();}});cp.add(Hold);resume.addActionListener(new ActionListener() {public void actionPerformed(ActionEvent e) {obj7_3th.fauxResume();}});cp.add(resume);}public static void main(String[] args) {ex7_3 obj7_3=new ex7_3();String str = obj7_3.getClass().toString();if(str.indexOf( class ) != -1)str = str.substring(6);JFrame frm = new JFrame(str);frm.addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent we) {System.exit(0);}});frm.getContentPane().add(obj7_3);frm.setSize(300, 200);obj7_3.init();obj7_3.start();frm.setVisible(true);}}ex7_3.htmlex7_3
点击查看答案&解析
问答题
基本操作题下面的程序是求菲波那契(Fibonacci)数列的前10项。已知该数列的前两项都为1,即F(1)=1,F(2)=1;而后面各项满足:F(n)=F(n-1)+F(n-2).请在程序的每条横线处填写一条语句,使程序的功能完整。注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。public class Fibonacci{public static void main(){System.out.println( Fibonacci is + + );}static long fib(int n){if( )return 1;elsereturn }}
点击查看答案&解析
相关试题
综合应用题下面是一个Applet程序,其功能是...
基本操作题下面的程序是求菲波那契(Fibona...