Skip to content

Commit 68efeb2

Browse files
committed
feat: Identify website protocol and domain type from URL input
🧠 Logic: - User enters a full URL string (e.g., `http://example.com`). - Protocol is extracted using `substring(0, indexOf(":"))`: - If `http` → prints "Hypertext Transfer Protocol" - If `ftp` → prints "File Transfer Protocol" - Else → prints "Unknown protocol" - Domain extension is extracted using `substring(lastIndexOf(".") + 1)`: - If `com` → prints "Commercial website" - If `org` → prints "Organization website" - If `net` → prints "Network website" - Else → prints "Unknown website type". Signed-off-by: Somesh diwan <[email protected]>
1 parent 8f41468 commit 68efeb2

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

Section7ConditionalStatements/src/ConditionalStatementsAB7.java

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
22
find a type of website and the protocol.
3-
is it goverment website, private, or org website.
3+
4+
is it a government website, private, or org website?
45
*/
56

67
import java.util.Scanner;
@@ -49,36 +50,29 @@ else if ("Net")
4950
// Extract the protocol
5051
String protocol = url.substring(0, url.indexOf(":"));
5152

52-
if (protocol.equals("http"))
53-
{
53+
if (protocol.equals("http")) {
5454
System.out.println("Hypertext Transfer Protocol");
5555
}
56-
else if (protocol.equals("ftp"))
57-
{
56+
else if (protocol.equals("ftp")) {
5857
System.out.println("File Transfer Protocol");
5958
}
60-
else
61-
{
59+
else {
6260
System.out.println("Unknown protocol");
6361
}
6462

6563
// Extract the domain type
6664
String ext = url.substring(url.lastIndexOf(".") + 1);
6765

68-
if (ext.equals("com"))
69-
{
66+
if (ext.equals("com")) {
7067
System.out.println("Commercial website");
7168
}
72-
else if (ext.equals("org"))
73-
{
69+
else if (ext.equals("org")) {
7470
System.out.println("Organization website");
7571
}
76-
else if (ext.equals("net"))
77-
{
72+
else if (ext.equals("net")) {
7873
System.out.println("Network website");
7974
}
80-
else
81-
{
75+
else {
8276
System.out.println("Unknown website type");
8377
}
8478
}

0 commit comments

Comments
 (0)