解题思路:
注意事项:
非数字类型在转换为数字类型时程序可能发生异常
参考代码:
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); while (sc.hasNext()) { String str=sc.next(); //. 、 $、 | 和 * 等转义字符前必须得加 “\\”进行分割 String strs[]=str.toString().split("\\."); char ch='Y'; for (int i = 0; i < strs.length; i++) { //startsWith:测试此字符串是否以指定的前缀(0)开始。 //如果参数表示的字符序列是此字符串表示的字符序列的前缀,则返回 true;否则返回 false。 //还要注意,如果参数是空字符串,或者等于此 String 对象(用 equals(Object) 方法确定),则返回 true。 if (strs[i].startsWith("0")) { ch = 'N'; break; } //try{} catch(Exception e){}:异常处理(catch在try发生异常时进入) try { if (Integer.parseInt(strs[i])<0||Integer.parseInt(strs[i])>255) { ch='N'; break; } else { } } catch (Exception e) { ch='N'; break; } } System.out.println(ch); } } }
0.0分
5 人评分
C语言训练-自守数问题 (C语言代码) long long浏览:1062 |
C语言训练-舍罕王的失算 (C语言代码)浏览:1033 |
简单的a+b (C语言代码)浏览:726 |
C语言程序设计教程(第三版)课后习题6.4 (C语言代码)浏览:544 |
【绝对值排序】 (C++代码)浏览:672 |
【蟠桃记】 (C语言代码)浏览:1024 |
C语言考试练习题_保留字母 (C语言代码)浏览:700 |
DNA (C语言描述,蓝桥杯)浏览:1553 |
字符串输入输出函数 (C语言代码)浏览:2485 |
C二级辅导-计负均正 (C语言代码)浏览:480 |