问答题

请完成下列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<str.length();i++){ _______________; _______________; System.out.print(ch); } }catch(IOException e){} try{ System.in.read(); }catch(IOException e) {}; } }

【参考答案】

ch=str.charAt(i) ch=(char)(’Z’ -ch+’A’)[解析] 本题主要考查字符串的操作和I/O......

(↓↓↓ 点击下方‘点击查看答案’看完整答案 ↓↓↓)
热门 试题

问答题
下面是一个Applet程序,其功能是显示有闪烁特效的从左向右的滚动文字。要求定义6种颜色:RED,GREEN,ORANGE, GRAY,YELLOW,BLUE,让文字在滚动过程中根据文字的位置循环选定—种颜色,并快速切换,达到一边移动一边闪烁的效果,同时要求通过htm1文件传递所显示的文字和延迟时间的参数,Applet程序能够根据参数实现显示功能。请改正程序中的错误(有下划线的语句),使程序能输山正确的结果。注意:不改动程序的结构,不得增行或删行。程序运行结果如下:import java.applet.Applet;import java.awt.*; *<applet code= ex12_3.class width=800 height=400 ><param name=text value= Welcome to NCR Examination! ><param name=delay value= 50 >< applet>* public class ex12_3 extends Applet implements Runnable{private String strText;private Thread thMover = null;private int nX, nY, nDelay;private Font fFont ;private int getParameter(String s1, int s2){String s = getParameter(s1) ;return (s != null) IntegerparseInt(s) : s2 ;}private String getParameter(String s1, String s2){String s = getParameter(s1) ;return (s != null) Integer.parseInt(s) : s2 ;}public void init(){fFont = new Font( TimesRome , Font.BOLD, 40) ;setBackground(Color.black);strText = getParameter( text , Put your message in strText parm );nX = getSize().height;nY = 80 ;nDelay = getParameter( delay , 80) ;}public void start(){if(thMover == null){thMover = new Thread(this);thMover.start();}}public void stop() {thMover = null;}public void run(){while(thMover != null){try{Thread.sleep(nDelay);}catch(InterruptedException e) { }repaint ( );}}public void paint(Graphics g){switch(nX % 6){case 0: g.setColor(Color. RED);break;case 1: g.setColor(Color. GREEN)break;case 2: g.setColor(Color. ORANGE;break;case 3: g.setColor(Color.GRAY);break;case 4: g.setColor(Color.YELLOW ;break;case 5: g.setColor(Color. BLUE);}g.setFont(fFont);g.drawString(strText, nX, nY);if(nX <= 0)nX= getSize ( ) .width ;}}ex12 3.htm1<HTML><HEAD><TITLE>ex12_3< TITLE>< HEAD><BODY><applet code= exl2_3.class width=800 height=400 ><param name=text value= Welcome to NCR Examination! ><param name=delay value= 50 >< applet>< BODY>< HTML>