守形数是这样一种整数,它的平方的低位部分等于它本身。 比如25的平方是625,低位部分是25,因此25是一个守形数。 编一个程序,判断N是否为守形数。
输入描述: 输入包括1个整数N,2<=N<100。
输出描述: 可能有多组测试数据,对于每组数据, 输出"Yes!”表示N是守形数。 输出"No!”表示N不是守形数。 示例1 输入 25 4 输出 Yes! No!
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNext()){ int n = scanner.nextInt(); if (String.valueOf(n * n).endsWith( String.valueOf(n))) System.out.println("Yes!"); else System.out.println("No!"); } } } 链接:https://www.nowcoder.com/questionTerminal/184edec193864f0985ad2684fbc86841?pos=174&orderByHotValue=1 来源:牛客网密码要求:
1.长度超过8位
2.包括大小写字母.数字.其它符号,以上四种至少三种
3.不能有相同长度大于等于2的子串重复
输入描述: 一组或多组长度超过2的子符串。每组占一行
输出描述: 如果符合要求输出:OK,否则输出NG
示例1 输入 021Abc9000 021Abc9Abc1 021ABC9000 021$bc9000 输出 OK NG NG OK
import java.util.*; public class Main { // 1.长度超过8位 public static boolean checkLength(String password){ if (password==null || password.length()<=8) return false; return true; } // 2.包括大小写字母.数字.其它符号,以上四种至少三种 public static boolean checkCharKinds(String password){ int Digit=0 , lowercase=0,uppercase=0,others=0; char[] ch = password.toCharArray(); for (int i = 0; i < ch.length; i++) { if (ch[i]>='0'&&ch[i]<='9') { Digit=1; continue; } else if (ch[i]>='a'&&ch[i]<='z') { lowercase=1; continue; } else if (ch[i]>='A'&&ch[i]<='Z') { uppercase=1; continue; }else { others=1; continue; } } int total = Digit+lowercase+uppercase+others; return total>=3 ? true : false; } // 3.不能有相同长度超2的子串重复 public static boolean checkCharRepeat(String password){ for(int i=0 ;i<password.length()-2 ;i++){ String substr1 =password.substring(i, i+3); if (password.substring(i+1).contains(substr1)) return false; } return true; } public static void main(String[] args) { Scanner cin = new Scanner(System.in); while (cin.hasNextLine()) { String psw = cin.nextLine(); if (checkLength(psw)&&checkCharKinds(psw)&&checkCharRepeat(psw)) System.out.println("OK"); else System.out.println("NG"); } } }