Java暑期学习第三十五天日报

一、今日学习内容:

今天练习了第二章的习题。

二、遇到的问题:

无。

三、明日计划:

明天计划练习第三章的例题。

 

今天学习的具体内容如下:

 3.写出下面程序运行的结果。请先阅读程序分析应输出的结果,然后上机验证。

public class t2 {
    public static void main(String[] args) {
        char c1='a',c2='b',c3='c',c4='\101',c5='\116';
        System.out.println(c1+c2+c3);
        System.out.print("\t\b"+c4+"\t"+c5+"\n");
        System.exit(0);
    }
    
}

测试截图:

 

 

 

4.写出下面程序运行的结果。请先阅读程序分析应输出的结果,然后上机验证。

public class t2 {
    public static void main(String[] args) {
        char c1='C',c2='+',c3='+';
        System.out.println("I say:\""+c1+c2+c3+'\"');
        System.out.print("\t\t"+"He says :\"C++ is very instering \""+"\n");
        System.exit(0);
    }
    
}

测试截图:

 

 

 

7.写出下面程序运行的结果。请先阅读程序分析应输出的结果,然后上机验证。

public class t2 {
    public static void main(String[] args) {
        int i,j,m,n;
        i=8;
        j=10;
        m=++i+j++;
        n=(i++)+(++j)+m;
        System.out.print(i+"\t"+j+"\t"+m+"\t"+n+"\n");
        System.exit(0);
    }
    
}

测试截图;

 

 

 

8.将China译成密码,密码规律是用原来的字母,后面第4个字母代替原来的字母。例如字母A后面第四个字母是E用E代表A,因此,China,音译为Gimre。请编写一程序,用付出值的方法使c1 c2 c2 c3 c4 c5 五个变量的值分别为C h i n a,经过运算是c1 c2  c3 c4 c5分别变为Gimre并输出

import java.util.Scanner;
public class t2 {
    public static void main(String[] args) {
        char c1,c2,c3,c4,c5;
        Scanner sc=new Scanner(System.in);
        System.out.println("请输入要赋给的单词:");
        String s=sc.next();
        c1=s.charAt(0);
        c2=s.charAt(1);
        c3=s.charAt(2);
        c4=s.charAt(3);
        c5=s.charAt(4);
        System.out.println("加密后的单词为:");
        System.out.print(change(c1));
        System.out.print(change(c2));
        System.out.print(change(c3));
        System.out.print(change(c4));
        System.out.print(change(c5));
        System.exit(0);
    }
    public static char change(char x) {
        char y;
        y=(char) ((int)x+4);
        return y;
    }
    
}

测试截图:

 

posted on 2020-08-09 17:48  桑榆非晚柠月如风  阅读(102)  评论(0编辑  收藏  举报