-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjumping.java
More file actions
63 lines (62 loc) · 1.05 KB
/
jumping.java
File metadata and controls
63 lines (62 loc) · 1.05 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
package practice;
import java.util.*;
public class jumping
{
ArrayList<Integer> al=new ArrayList<Integer>();
void print1(int x,int num)
{
Queue<Integer> q1=new LinkedList<Integer>();
q1.add(num);
while(!q1.isEmpty())
{
num=q1.peek();
q1.poll();
if(num<=x)
{
al.add(num);
int last=num%10;
if(last==0)
{
q1.add((num*10)+(last+1));
}
else if(last==9)
{
q1.add((num*10)+(last-1));
}
else
{
q1.add((num*10)+(last-1));
q1.add((num*10)+(last+1));
}
}
}
}
void print(int x)
{
al.add(0);
for(int i=1;i<=9&&i<=x;i++)
{
print1(x,i);
}
Collections.sort(al);
for(int i=0;i<al.size();i++)
{
System.out.print(al.get(i)+" ");
}
System.out.println();
al.clear();
}
public static void main(String args[])
{
Scanner sc=new Scanner(System.in);
jumping j=new jumping();
System.out.println("Enter the no of testcases");
int test=sc.nextInt();
for(int i=0;i<test;i++)
{
System.out.println("Enter the no");
int no=sc.nextInt();
j.print(no);
}
}
}