
Java关于IP地址的程序
IPaddressesaremadeupoffournumbers,eachbetween0and255separatedbyaperiod.Forexample,128...
IP addresses are made up of four numbers, each between 0 and 255 separated by a period. For example, 128.253.21.58 is an IP address.
Write a program to enter four numbers and test if they make up a valid IP address. In other words, test to see if the numbers entered are between 0 and 255 inclusive.
Sample Run 1:
Please enter the first octet:898
Please enter the second octet:34
Please enter the third octet:712
Please enter the fourth octet:45
Octet 1 is incorrect
Octet 3 is incorrect
Sample Run 2:
Please enter the first octet::112
Please enter the second octet:200
Please enter the third octet:0
Please enter the fourth octet:254
IP Address: 112.200.0.254
ip地址有4个0-255的数字组成,比如1.3.2.255
怎么写一个程序让用户输入
4个整数,如果有一个大于255或者小于0,就print 第几个错了
如果都没错就print ip地址。
例子1:
第1次输入:1
第2次输入:2
第3次输入:3
第4次输入:4
输出:1.2.3.4
例子2:
第1次输入:1
第2次输入:255
第3次输入:3
第4次输入:4
输出:第二个错误
我写的,但是不正确,求支出错误
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.println("Please enter 4 inter from 0 to 255");
int a = scan.nextInt();
int b = scan.nextInt();
int c = scan.nextInt();
int d = scan.nextInt();
if (a>=0&&a<=255)
{
if( b>=0&&d<=255)
{
if (c>=0&&d<=255)
{
if (d>=0&&d<=255)
{
System.out.print(a+"."+b+"."+c+"."+d);
}
else
{
System.out.print("test 4 is not valid");
}
}
else
{
System.out.print("test 3 is not valid");
}
}else
{
System.out.print("test 2 is not valid");
}
}
else
{
System.out.print("test 1 is not valid");
}
上文中的例子2错的。应该是
例子2:
第1次输入:1
第2次输入:256
第3次输入:3
第4次输入:4
输出:第二个错误 展开
Write a program to enter four numbers and test if they make up a valid IP address. In other words, test to see if the numbers entered are between 0 and 255 inclusive.
Sample Run 1:
Please enter the first octet:898
Please enter the second octet:34
Please enter the third octet:712
Please enter the fourth octet:45
Octet 1 is incorrect
Octet 3 is incorrect
Sample Run 2:
Please enter the first octet::112
Please enter the second octet:200
Please enter the third octet:0
Please enter the fourth octet:254
IP Address: 112.200.0.254
ip地址有4个0-255的数字组成,比如1.3.2.255
怎么写一个程序让用户输入
4个整数,如果有一个大于255或者小于0,就print 第几个错了
如果都没错就print ip地址。
例子1:
第1次输入:1
第2次输入:2
第3次输入:3
第4次输入:4
输出:1.2.3.4
例子2:
第1次输入:1
第2次输入:255
第3次输入:3
第4次输入:4
输出:第二个错误
我写的,但是不正确,求支出错误
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.println("Please enter 4 inter from 0 to 255");
int a = scan.nextInt();
int b = scan.nextInt();
int c = scan.nextInt();
int d = scan.nextInt();
if (a>=0&&a<=255)
{
if( b>=0&&d<=255)
{
if (c>=0&&d<=255)
{
if (d>=0&&d<=255)
{
System.out.print(a+"."+b+"."+c+"."+d);
}
else
{
System.out.print("test 4 is not valid");
}
}
else
{
System.out.print("test 3 is not valid");
}
}else
{
System.out.print("test 2 is not valid");
}
}
else
{
System.out.print("test 1 is not valid");
}
上文中的例子2错的。应该是
例子2:
第1次输入:1
第2次输入:256
第3次输入:3
第4次输入:4
输出:第二个错误 展开
1个回答
推荐于2016-07-11
展开全部
if( b>=0&&d<=255)
{
if (c>=0&&d<=255)
{
if (d>=0&&d<=255)
{
System.out.print(a+"."+b+"."+c+"."+d);这里后面判断的都是d,改成:
if( b>=0&&b<=255)
{
if (c>=0&&c<=255)
{
if (d>=0&&d<=255)
{
System.out.print(a+"."+b+"."+c+"."+d);就行
{
if (c>=0&&d<=255)
{
if (d>=0&&d<=255)
{
System.out.print(a+"."+b+"."+c+"."+d);这里后面判断的都是d,改成:
if( b>=0&&b<=255)
{
if (c>=0&&c<=255)
{
if (d>=0&&d<=255)
{
System.out.print(a+"."+b+"."+c+"."+d);就行
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?

2023-07-25 广告
StormProxies是一家提供动态代理服务器服务的企业,旨在帮助用户更好地管理网络访问和安全。以下是一些关于StormProxies的IP动态代理服务的特点:1. 高匿名性:StormProxies的动态代理服务器具有高匿名性,可以有效...
点击进入详情页
本回答由Storm代理提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |