English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
给定字节数组广告,任务是使用Java中的IPAddress类将其转换为IP地址并显示结果。
一个字节由8位组成,字节数组由多个连续字节组成,这些字节存储二进制信息。在Java中,byte是一种原始数据类型,可以理解为计算机的字节,即8位,可以保存-128至127的值。
声明一个字节-byte name_of_byte_variable = value_assigned;
Dichiarare un array di byte-byte [] name_of_byte_array = new byte [];
In Java, la classe IPAddress viene utilizzata per ottenere l'indirizzo IP di qualsiasi sistema. Esiste nella classe System.net e deve essere importata per utilizzare la classe IPAddress.
IPAddress ObjectName = new IPAddress(byte[])
Input-: 171, 32, 101, 11 Output-: 171.32.101.11 Input-: 172, 31, 102, 14 Output-: 172.31.102.14
I metodi che usiamo nel seguente programma sono i seguenti-
Importare la classe System.net
Inserire i numeri come byte nell'array di byte
Creare un oggetto della classe IPAddress e passare un array di byte al suo oggetto
Usare la funzioneToString()
Convertire l'indirizzo in una rappresentazione di stringa
Stampare il risultato
START Passo 1-> dichiarare la classe convert per la conversione public class convert call class public static void Main() set IPAddress add = new IPAddress(new byte[] { 171, 32, 101, 11 }) call Console.WriteLine(add.ToString()) End End STOP
using System; using System.Net; public class convert { public static void Main() { IPAddress add = new IPAddress(new byte[] { 171, 32, 101, 11 }); Console.WriteLine(add.ToString()); } }
Risultato di output
171.32.101.11