Java编写测试类,输入一个标准的网址,输出其域名的主体; 将该主体转换为大写,打印输出 测试输入: https://www.educoder.net/ 预期输出: educoder EDUCODER
时间: 2024-05-20 08:17:50 浏览: 10
public class TestDomain {
public static void main(String[] args) {
String url = "https://www.educoder.net/";
String domain = getDomain(url);
System.out.println(domain.toUpperCase());
}
public static String getDomain(String url) {
String domain = "";
if (url == null || url.equals("")) {
return domain;
}
int start = url.indexOf(".") + 1;
int end = url.indexOf(".", start);
if (end == -1) {
end = url.length();
}
domain = url.substring(start, end);
return domain;
}
}
相关问题
编写Java应用程序,输入一个十进制数,转换为二进制数输出
好的,让我来帮您编写这个 Java 应用程序。以下是代码示例:
```
import java.util.Scanner;
public class DecimalToBinary {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("请输入一个十进制数:");
int decimal = input.nextInt();
String binary = convertDecimalToBinary(decimal);
System.out.println(decimal + " 的二进制表示为:" + binary);
}
public static String convertDecimalToBinary(int decimal) {
String binary = "";
while (decimal > 0) {
int remainder = decimal % 2;
binary = remainder + binary;
decimal = decimal / 2;
}
return binary;
}
}
```
这个程序首先会提示用户输入一个十进制数。然后,它会调用一个名为 `convertDecimalToBinary` 的方法,将输入的数值转换为二进制数。最后,程序会将转换后的二进制数输出到屏幕上。
您可以将以上代码复制到一个 Java 编辑器中,然后运行它来测试它是否能够正确地将输入的十进制数转换为二进制数。感谢您使用 CSDN 开发的 C 知道。
python编写一个类MyMath,测试输入一个参数,输出以此为半径的圆与求的各项属性
好的,以下是一个简单的实现:
```python
import math
class MyMath:
def __init__(self, radius):
self.radius = radius
def get_diameter(self):
return self.radius * 2
def get_circumference(self):
return 2 * math.pi * self.radius
def get_area(self):
return math.pi * self.radius ** 2
# 测试
my_circle = MyMath(5)
print("半径为", my_circle.radius)
print("直径为", my_circle.get_diameter())
print("周长为", my_circle.get_circumference())
print("面积为", my_circle.get_area())
```
输出结果如下:
```
半径为 5
直径为 10
周长为 31.41592653589793
面积为 78.53981633974483
```
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)