-
Notifications
You must be signed in to change notification settings - Fork 0
/
P44_Card.java
63 lines (58 loc) · 1.49 KB
/
P44_Card.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
public class P44_Card {
public void isContinus( int [] array)
{
if(array == null )
{System.out.println("The array is NULL!");
return;
}
if(array.length<=0)
{
System.out.println("The array is EMPTY !");
return;
}
System.out.println(" 1 means A \n11 means J \n12 means Q \n13 means K\n 0 means Read&Black Joker ");
int joker =0;
int gap =0;
QuickSort qs = new QuickSort();
qs.sort(array);
qs.display(array);
for(int index =array.length-1;index>=0;index--){
if(array[index] ==0)
joker++;
else if(index>1 && array[index-1]>0)
{ if(array[index]==array[index-1])
{
gap = Integer.MAX_VALUE;
break;
}
gap += array[index]-array[index-1]-1;
}
}
if(joker>=gap)
System.out.println("The five cards is continus! joker = "+joker+", gap = "+gap);
else
System.out.println("The five cards is NOT continus! joker = "+joker+", gap = "+gap);
}
public static void main(String [] args)
{
P44_Card test = new P44_Card ();
//test
//founction test
System.out.println("Founction Test:");
int [] array ={1,2,3,0,0};
test.isContinus(array);
int [] arrayNo = {1,6,3,9,0};
test.isContinus(arrayNo);
//boundary test
System.out.println("\nBoundary Test:");
int []array00 ={9,13,12,0,0};
test.isContinus(array00);
int []arrayPair ={9,9,12,0,0};
test.isContinus(arrayPair);
//exception test
System.out.println("\nException Test:");
int [] arrayEmpty = {};
test.isContinus(arrayEmpty);
test.isContinus(null);
}
}