-9

how can I convert IPv4 to four several integers.?
Here is some example:

This is an input: 158.195.16.154

And I want output like this:

int a=158;

int b=195;

int c=16;

int d=154;

Thx for the answers.

JaFu
  • 11
  • 2

2 Answers2

0
String ip = "158.195.16.154";
String[] tokens = ip.split("\\.");
int[] numbers = new int[tokens.lenght];
for (int i = 0; i<tokens.lenght; i++) numbers[i] = Integer.parseInt(tokens[i]);
Fedy2
  • 3,147
  • 4
  • 26
  • 44
0
String Ip = "158.195.16.154";
String[] arr = Ip.split("\\.");
int[] intIp = new int[4];
int i=0;

for(String s:arr){
    intIp[i] = Integer.parseInt(s);
}
zkanoca
  • 9,664
  • 9
  • 50
  • 94
SeeTheC
  • 1,560
  • 12
  • 14