尚学堂JAVA第二章编码题答案参考
尚学堂JAVA第二章编码题答案参考
本文章为本人个人编辑,仅供自己学习和自我监督。如有读者发现问题,请留言提醒本人修改。谢谢
第一题
import java.util.Scanner;
/**
* 第二章作业1
* @author sandu
*
*/
public class DierzhangZuoye {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
System.out.println("请输入圆的半径: ");
double banjing = scanner.nextDouble();
System.out.println("该圆的半径为: "+banjing);
System.out.println("该圆的周长为: "+banjing*2*3.14);
System.out.println("该圆的面积为: "+3.14*banjing*banjing);
}
}
第二题
import java.util.Scanner;
/**
* 第二章编程第二题
* @author sandu
*
*/
public class DierzhangZuoye2 {
public static void main (String[] args){
Scanner scanner = new Scanner(System.in);
System.out.println("请输入你的本金,将自动计算本息合计");
int BJ = scanner.nextInt();
System.out.println("活期一年本息总计 : "+(BJ+BJ*0.0035));
System.out.println("定期1年本息总计:"+(BJ+BJ*0.015));
System.out.println("活期两年本息总计 : "+(BJ+BJ*0.007));
System.out.println("定期两年本息总计:"+(BJ+BJ*0.021));
}
}
第三题
import java.util.Scanner;
/**
* 第二章编程第三题
* @author sandu
*
*/
public class DierzhangZuoye3 {
public static void main (String [] args){
Scanner scanner = new Scanner(System.in);
System.out.println("请输入一个四位整数:");
int a = scanner.nextInt();
int a1 = ((a%10)+5)%10;
int a2 = ((a%100/10)+5)%10;
int a3 = ((a%1000/100)+5)%10;
int a4 = ((a%10000/1000)+5)%10;
int b = a1*1000+a2*100+a3*10+a4;
System.out.println("加密后的数字为:"+b);
}
}