JAVA编程练习

回文数

判断一个整数是否是回文数。回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数。

class Solution {
    public boolean isPalindrome(int x) {
        if(x<0)
            return false;
        int i=0,j=0;
        int k=x;
        while(k!=0){
            i=k%10;
            j=j*10+i;
            k=k/10;
        }
        return j==x;
    }
}

确定数据类型

public class Main{
    public static void main(String[] args){
        System.out.println("The size of short is "+Short.SIZE/8+" bytes.");
        System.out.println("The size of int is "+Integer.SIZE/8+" bytes.");
        System.out.println("The size of long is "+Long.SIZE/8+" bytes.");
        System.out.println("The size of long long is "+Long.SIZE/8+" bytes.");
    }
}

图案顺序

KiKi学会了printf在屏幕输出信息,他想输出一架小飞机。请帮他编写程序输出这架小飞机。
输出:在这里插入图片描述

public class Main{
    // 定义一个静态字符串数组,每一行就是一次的数组输出
    static String[] s1 = null;
    public static void main(String[] args){
        // 生成一行中第5、6个是*号其余为空格的行
        change(5,6);
        // 展示一次
        show();
        // 再展示一次
        show();
        // 生成全是*号的行
        change(-1,-1);
        show();
        show();
        // 同理
        change(4,7);
        show();
        show();
    }
    // 改变数组的状态,决定一行中哪一个是*号哪一个是空格
    // first是一行中第一次出现*号的索引,last则是最后一次
    public static void change(int first,int last){
        // 进来先把数组给初始化,里边都是默认值null
        s1 = new String[12];
        // 一行中不是*号就是空格
        String x = "*";
        String y = " ";
        // 循环填充数组的值
        for(int i = 0; i < s1.length; ++i){
            // 这里是处理那些行中,有*号又有空格号的
            if(first > 0){
                s1[i] = y;
                s1[first] = x;
                s1[last] = x;
            }else{
                // 这里则处理那些全是*号的行
                s1[i] = x;
            }
        } 
    }
    // 这个函数主要用来输出数组
    public static void show(){
        for(String s: s1){
            System.out.print(s);
        }
        System.out.println();
    }
}

题目来源
来源:力扣(LeetCode)
链接:https://leetcode-cn.com
来源:牛客
链接:https://www.nowcoder.com

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值