zoukankan      html  css  js  c++  java
  • 每日练习

    package com.feng;
    /*需求:打印以下图像
     *     *
     *     **
     *     ***
     *     ****
     *     *****
     * 思路:利用嵌套循环。
     *         外循环控制行数,内循环控制列数。
     *         如图所式:每一行图形的个数等于行数
     * 
     * 
     */
    public class ForTest {
        public static void main(String[] args){
            //外循环控制行数,内循环控制列数
            for(int x=1;x<=5;x++){
                for(int y=1;y<=x;y++){
                    System.out.print("*");
                }
                System.out.println();
            }
        }
    }
    package com.feng;
    /*
     * 需求:打印9*9乘法表
     * 
     * 
     */
    public class NineNine {
        public static void main(String[] args){
            for(int x=1;x<10;x++){
                for(int y=1;y<=x;y++){
                    System.out.print(y+"*"+x+"="+x*y+"	");
                }
                System.out.println();
            }
        }
    }
    package com.feng;
    
    import java.util.Scanner;
    
    /*
     * 需求:编写一个程序,读取一个0到1000之间的整数,并将该整数的各位数字
     * 相加求和
     * 思路:1、判断输入的数字是几位数,1位数?2位数?3位数?
     *        2、对于一位数直接显示
     *        3、对于2位数,先利用“/”求得十位数,再用“%”求得个位数,然后求和
     *        4、对于3位数,同2位数一样    
     * 
     * 
     */
    public class Demo1 {
        public static void main(String[] args){
            //读取数字
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入一个0到1000的整数:");
            int a = sc.nextInt();
            int sum =0;
            //判断是几位数
            for(;;){
            if(0<a && a<10){
                sum =a;
                System.out.println("你输入的数字的各个位数之和为"+sum);
                break;
            }else if(a>=10 && a<100){
                int b = a/10;
                int c = a%10;
                sum = b+c;
                System.out.println("你输入的数字的各个位数之和为"+sum);
                break;
            }else if(a>=100&&a<=1000){
                int b = a/100;
                int c =(a-b*100)/10;
                int d = a%10;
                sum =b+c+d;
                System.out.println("你输入的数字的各个位数之和为"+sum);
                break;
            }else{
                System.out.println("你输入的数字超出范围,请重新输入一个0到1000的整数");
                a =sc.nextInt();
            }
          }
        }
        
    }
    package com.feng;
    
    import java.util.Scanner;
    
    /**
     * 编写一个程序,接受以ASCII码(从0到128),然后显示它
     * 所代表的字符
     * 
     * @author flzen
     *
     */
    public class Demo2 {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入一个0到128的数字:");
            int a = sc.nextInt();
            //判断
            if(a>=0&&a<=128){
                System.out.println("你输入的数字对应的ASCII的字符是"+(char)a);
            }else{
                System.out.println("你输入的数字有误");
            }
        }
    }
    package com.feng;
    
    import java.util.Scanner;
    
    /**
     * 需求:假设你每月向银行存1000块钱,年利率是5%,
     * 那么月利率就是0.05/12 =0.00417。
     * 第一个月,账户上的值就变成了:
     *             1000*(1+0.00417)=1004.17;
     * 第二个月,账户上的值就变成了
     *             (1000+1004.17)*(1+0.00417)=2012.52
     * 第3个月,账户上的钱就变成了
     *             (1000+2012.52)*(1+0.00417)=3025.07
     * 编写程序,当用户输入他每月纯的钱,年利率,需要查询的月数后,显示账户上的总值
     * 
     * @author flzen
     *
     */
    public class Demo3 {
        public static void main(String[] args) {
            //用户输入需要查询的月数
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入年利率");
            double x = sc.nextDouble();
            System.out.println("请输入每月存入的钱:");
            double y = sc.nextDouble();
            for(;;){
            System.out.println("请您输入您要查询的月数:");
            int a = sc.nextInt();
            double sum = ((y*(1+x/12)*(a-1)+y*Math.pow((1+x/12), a)))*100/100.0;
            System.out.println(sum);
            }
            
        }
    }
  • 相关阅读:
    单调队列
    Johnson全源最短路
    重链剖分
    矩阵快速幂
    Tarjan
    题解 UVA439 骑士的移动 Knight Moves
    题解 SP10500 HAYBALE
    题解 P4058 [Code+#1]木材
    题解 P3395 路障
    题解 SP24 FCTRL2
  • 原文地址:https://www.cnblogs.com/flei/p/6822784.html
Copyright © 2011-2022 走看看