Java教程

Java

本文主要是介绍Java,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

import java.util.Scanner;
public class Main {

public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String ip = in.nextLine();
String ziwang = in.nextLine();
String[] a = {"0","0","0","0"};
String[] b = {"0","0","0","0"};
String[] res = {"0","0","0","0"};
a[0] = ip.split(".")[0];
System.out.println(a[0]);
//int length = a.length;
//System.out.println(a[0]);

for(int i=0; i<4; i++) {
a[i] = ip.split(".")[i];
b[i] =ziwang.split(".")[i];
res[i] = Integer.toString(Integer.parseInt(a[i]) &Integer.parseInt(b[i]));
}
for(String m:res) {
System.out.println(m);
}



}

static String binary2decimal(int decNum , int digit) {
String binStr = "";
for(int i= digit-1;i>=0;i--) {
binStr +=(decNum>>i)&1;
}
return binStr;
}


}

 有问题  Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0

这篇关于Java的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!