-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest_NonRainbow.java
More file actions
38 lines (35 loc) · 795 Bytes
/
Copy pathTest_NonRainbow.java
File metadata and controls
38 lines (35 loc) · 795 Bytes
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
import java.util.*;
class NonRainbowColour extends Exception
{
public NonRainbowColour(String s)
{
super(s);
}
}
class Test_NonRainbow
{
public static void main(String[] args)
{
String rb[] = { "violet", "indigo", "blue", "yellow", "green", "orange", "red"};
List<String> list = Arrays.asList(rb);
String c, s;
Scanner sc = new Scanner(System.in);
System.out.println("Rithik Kanojia - 18075");
System.out.print("Enter a colour : ");
c = sc.next();
s = c.toLowerCase();
try
{
if (list.contains(s))
{
System.out.print("Colour entered is "+c+" and it is a rainbow colour");
}else
{
throw new InvalidSaarcException("Entered colour is not a Rainbow Colour");
}
}catch(InvalidSaarcException e)
{
System.out.println(e.toString());
}
}
}