-
Notifications
You must be signed in to change notification settings - Fork 0
/
clzexample.java
31 lines (23 loc) · 1004 Bytes
/
clzexample.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//Write a java program to accept the url from user and encode the url and display encoded url string and then decode the encoded url and display the decoded url.
import java.net.URLEncoder;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;
public class clzexample {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a URL: ");
String inputURL = scanner.nextLine();
try {
// Encode the URL
String encodedURL = URLEncoder.encode(inputURL, StandardCharsets.UTF_8.toString());
System.out.println("Encoded URL: " + encodedURL);
// Decode the URL
String decodedURL = URLDecoder.decode(encodedURL, StandardCharsets.UTF_8.toString());
System.out.println("Decoded URL: " + decodedURL);
} catch (Exception e) {
e.printStackTrace();
}
scanner.close();
}
}