解题思路:
注意事项:
参考代码:
package cWeb.buleCup; import java.util.Scanner; public class Main{ public static boolean HfNum(String ip) { int i = 0; int beginIndex = 0; int endIndex = 0; while(i<4) { if(i==3) { endIndex = ip.length(); }else { endIndex = ip.indexOf('.',endIndex+1); } String subip = ip.substring(beginIndex, endIndex); for(int i1=0;i1<subip.length();i1++) { if((subip.charAt(i1)>='a' && subip.charAt(i1)<='z') || (subip.charAt(i1)>='A' && subip.charAt(i1)<='Z')) { return false; } } if(Integer.valueOf(subip)<0 || Integer.valueOf(subip)>255) { return false; } beginIndex = endIndex+1; i++; } return true; } public static boolean HfPoint(String ip) { int pointNum = 0; for (int i = 0; i < ip.length(); i++) { if (ip.charAt(i) == '.') { pointNum++; } } if (pointNum == 4) { return true; } return false; } public static void main(String[] args) { // TODO Auto-generated method stub Scanner in = new Scanner(System.in); while (in.hasNext()) { String ip = in.nextLine(); if (ip.equals("End of file")) break; if (HfPoint(ip)) { System.out.println("N"); continue; } else { if (HfNum(ip)) { System.out.println("Y"); } else { System.out.println("N"); } } } } }
0.0分
0 人评分
人见人爱A+B (C语言代码)浏览:1046 |
C二级辅导-分段函数 (C语言代码)浏览:583 |
大神老白 (C语言代码)浏览:768 |
C语言程序设计教程(第三版)课后习题10.7 (C语言代码)浏览:556 |
C语言训练-求函数值 (C语言代码)浏览:976 |
哥德巴赫曾猜测 (C语言代码)浏览:2562 |
水仙花 (C语言代码)浏览:1163 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:438 |
C语言程序设计教程(第三版)课后习题10.1 (C语言代码)浏览:571 |
剪刀石头布 (C语言代码)浏览:1519 |