-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelloworld.java
More file actions
98 lines (81 loc) · 2.54 KB
/
Copy pathhelloworld.java
File metadata and controls
98 lines (81 loc) · 2.54 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*A number is a valid flight number given that it meets the following criteria:
a. The number is greater than 9 and no greater than 9999.
b. The number is a jumbled number*.
Please write a function that will provide a list of all valid flight numbers
that AA can use to number our flights.
What is the Big-O for your solution?
*A jumbled number is a number whose digits meet the following criterion:
*each digit differs by at most 1 from each of its neighboring digits.
*E.g. 8987 is a jumbled number, but 312 is not.
*/
package helloworld;
import java.util.*;
public class helloworld {
public static void main(String[] args) {
System.out.println("helloworld");
ArrayList<Integer> lists= new ArrayList<Integer>();
int x ,z , l , w , y , m , diff, diff1, diff2;
for (int i =10;i<10000;i++)
{
if(i<100){
x = i%10;
y = Math.abs((x*10)-(i-x));
if(y<11){
lists.add(i);
}
}
if(i>99){
x = i%100;
z = x%10;
w = i/100;
y = x/10;
diff = Math.abs(w-y);
diff1 = Math.abs(y-z);
if((diff)<2 && (diff1)<2) {
lists.add(i);
}
}
if(i>999){
x = i%1000;
z = x%100;
l = z%10;
w = i/1000;
y = x/100;
m = z/10;
diff = Math.abs(w-y);
diff1 = Math.abs(y-m);
diff2 = Math.abs(m-l);
if((diff)<2 && (diff1)<2 && (diff2)<2) {
lists.add(i);
}
}
}
System.out.println(lists);
}
}
/*
char[] chars=String.valueOf(i).toCharArray();
if(chars.length==2) {
int diff= (Character.getNumericValue(chars[chars.length-1])-Character.getNumericValue(chars[chars.length-2]));
if(Math.abs(diff)<2 ) {
lists.add(i);
//System.out.println(i);
}
}
if(chars.length==3) {
int diff= (Character.getNumericValue(chars[chars.length-3])-Character.getNumericValue(chars[chars.length-2]));
int diff1= (Character.getNumericValue(chars[chars.length-2])-Character.getNumericValue(chars[chars.length-1]));
if(Math.abs(diff)<2 && Math.abs(diff1)<2) {
lists.add(i);
//System.out.println(i%(i-1));
}
}
if(chars.length==4) {
int diff= (Character.getNumericValue(chars[chars.length-4])-Character.getNumericValue(chars[chars.length-3]));
int diff1= (Character.getNumericValue(chars[chars.length-3])-Character.getNumericValue(chars[chars.length-2]));
int diff2= (Character.getNumericValue(chars[chars.length-2])-Character.getNumericValue(chars[chars.length-1]));
if(Math.abs(diff)<2 && Math.abs(diff1)<2 && Math.abs(diff2)<2) {
lists.add(i);
}
}
*/