叮滴答


私信TA

用户名:cdd1999

访问量:2793

签 名:

等  级
排  名 1096
经  验 3114
参赛次数 0
文章发表 5
年  龄 0
在职情况 学生
学  校 河南农业大学
专  业

  自我简介:

解题思路:

注意事项:

参考代码:

import java.util.*;


public class Main{


public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

while (sc.hasNext()) {

String s = sc.nextLine();

if (s.equals("End of file")) {

break;

} else {

String[] arr = s.split("\\.");//切割成字符串数组

if (arr.length == 4) {判断数组的长度是否等于4

int temp = 0;//计数器计算是否含有除数字以外的其它字符

for (int i = 0; i < arr.length; i++) {

for (int j = 0; j < arr[i].length(); j++) {

if (!(arr[i].charAt(j) >= '0' && arr[i].charAt(j) <= '9')) {

temp++;

}

}

}

if (temp > 0) {//如果大于0说明含有其它字符

System.out.println("N");

} else {

int count = 0;//计数器计算符合条件的字符串数组中字符串元素的个数

for (int i = 0; i < arr.length; i++) {

int m = Integer.parseInt(arr[i]);

if ((m >= 0)

&& (m <= 255)

&& (Integer

.parseInt(arr[i].substring(0, 1)) != 0)) {

count++;

} else {

System.out.println("N");

break;

}

}

if (count == 4) {//如果四个都符合,就输出Y

System.out.println("Y");

}


}

}

}

}

}

}


 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区