Java判断数组元素是否对称

标题日期:2020/1/14

标题功能:判断数组元素是否对称

标题IDE:Intelli IDEA

package test.demo;

import com.sun.media.jfxmediaimpl.HostUtils;

public class SymmetryArray {
    public static void main(String[] args){
        boolean flag = true;
        int[] a = {1,6,2,1};
        int start = 0;
        int end = a.length-1;
        while (start<=end){
            if(a[start]!=a[end]){
                flag = false;
                break;
            }
            else{
                start++;
                end--;
            }
        }
        if(flag==true)
            System.out.println("对称");
        else
            System.out.println("不对称");
    }
}

发布了57 篇原创文章 · 获赞 2 · 访问量 1847

猜你喜欢

转载自blog.csdn.net/weixin_43476969/article/details/103970888