-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
44 lines (41 loc) · 1.68 KB
/
Main.java
File metadata and controls
44 lines (41 loc) · 1.68 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
URLShortener url=new URLShortener();
while (true) {
System.out.println("*****MENU*****");
System.out.println("1.Shorten URL");
System.out.println("2.Get Original URL");
System.out.println("3.Exit");
System.out.println("Enter your choice :");
int choice=sc.nextInt();
sc.nextLine();
switch (choice) {
case 1:
System.out.println("Enter the URL to shorten : ");
String longurl=sc.nextLine();
String res=url.shorttolong(longurl);
if(res.equals("Invalid URL"))
System.out.println("Invalid URL entered. Try again!");
else
System.out.println("Short URL : "+url.shorttolong(longurl));
break;
case 2:
System.out.println("Enter short URL : ");
String shorturl=sc.nextLine();
res=url.getOriginal(shorturl);
if(res.equals("Invalid URL"))
System.out.println("Invalid URL entered. Try again!");
else
System.out.println("Original URL : "+res);
break;
case 3:
System.out.println("Thank you for using URL Shortener!");
return;
default:
System.out.println("Invalid choice. Try again!");
}
}
}
}