题解 | #合法IP#
合法IP
http://www.nowcoder.com/practice/995b8a548827494699dc38c3e2a54ee9
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
String str = sc.nextLine();
String[] srr = str.split("\\.");
boolean flag=true;
for(String s : srr){
int temp = Integer.parseInt(s);
if(temp>=0 && temp<=255){
continue;
}else{
flag=false;
System.out.println("NO");
break;//遇到不合法的直接 打印break
}
}
if(flag){
//整个for循环结束后,都仍然是合法的,则输出yes
System.out.println("YES");
}
}
}
}