java题目初级小结,编写九九乘法表、打印实心、空心菱形、水仙花数、输出1~100之间不能被5整除的数,每5个一行

1.九九乘法表

public class study1 {
    public static void main(String[] args) {
        for(int i = 1;i <=9;i++){
            for(int j =1;j <= i;j++){
                System.out.print(j + "*" + i + "=" + (j*i) + "\t");
            }
            System.out.println( );
        }
    }
}

注意:加上制表位 \t 会使结果更加整洁哦!

 2. 打印实心、空心菱形

实心:
  Scanner sc = new Scanner(System.in);
        System.out.println("请输入你想打印实心菱形数,方法为,输入一个数a,得到的是2 * a - 1个层数的实心菱形:");
        int totalfloor = sc.nextInt();
        for (int i = 1;i <= totalfloor;i++){
            for(int j = 1;j <= totalfloor - i;j++){
                System.out.print(" ");
            }
                for(int k = 1;k <= 2*i-1;k++){
                    System.out.print("*");
                }
            System.out.println(" ");
        }
        for(int a = totalfloor - 1;a >= 1;a--){
            for(int b = 1;b <= totalfloor - a;b++){
                System.out.print(" ");
            }
            for(int c = 1;c <= 2 * a - 1;c++){
                System.out.print("*");
            }
            System.out.println(" ");
        }
空心:
{
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入你想打印空心菱形数,方法为,输入一个数a,得到的是2 * a - 1个层数的空心菱形:");
        int totalfloor = sc.nextInt();
        for (int i = 1;i <= totalfloor;i++){
            for(int j = 1;j <= totalfloor - i;j++){
                System.out.print(" ");
            }
                for(int k = 1;k <= 2 * i - 1;k++){
                    if(k == 1 || k == 2 * i - 1 ){
                        System.out.print("*");
                    }
                    else{
                        System.out.print(" ");
                    }
                }
            System.out.println(" ");
        }
        for(int a = totalfloor - 1;a >= 1;a--){
            for(int b = 1;b <= totalfloor - a;b++){
                System.out.print(" ");
            }
            for(int c = 1;c <= 2 * a - 1;c++){
                if(c == 1 || c == 2 * a - 1){
                System.out.print("*");
                }
                else{
                    System.out.print(" ");
                }
            }
            System.out.println(" ");
        }
    }

3.水仙花数  

while(true) {
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入一个三位数,即可判断此数是不是水仙花树:");
            int number = sc.nextInt();
            int a = number / 100;//得到百位上的数
            int b = number % 100; // 得到除了百位上的其他位数
            int c = number % 10; //个位
            int d = b / 10; //十位
            if (number == a * a * a + c * c * c + d * d * d) {
                System.out.println("您输入的数为水仙花树");
                break;
            } else {
                System.out.println("您输入的不是,请在此输入!");
            }

注:用while循环,通过输入数字,判断是否为水仙花数,直至输入的数字为水仙花树!

 4.输出1~100不能被5整除的数,每输入5个换行

 public static void main(String[] args) {
        int count = 0;
       for(int i = 1;i <= 100;i++){
           if(i % 5 == 0){
               continue;
           }
           else{
               System.out.print(i + " ");
               count++;
               if(count % 5 ==0){
                   System.out.println(" ");
               }
         }
    }

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值