AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



programming-basics: Find nth number in a number system with only 3 and 4

Given a number system with only 3 and 4. Find the nth number in the number system. First few numbers in the number system are: 3, 4, 33, 34, 43, 44, 333, 334, 343, 344......

programming x 167
basics x 170
Posted On : 2017-08-08 18:16:06.0
profile Divesh - anyforum.in Divesh
102180
up-rate
5
down-rate

Answers


public class CombinationSeriesGenerator {
public static void main(String[] args) {
int n=8;
Integer[] series=getCombinationSeries(´3´,´4´,n);

System.out.println(series[n-1]);
}

public static Integer[] getCombinationSeries(char ch1, char ch2, int n){
String[] series=new String[n];
series[0]=Character.toString(ch1);
series[1]=Character.toString(ch2);
int count=2;
int startIndex=0;
int index=0;
int last=0;
while(count<n){
index=startIndex;
last=count;
for(int i=startIndex;i<last;i++){
if(count>=n)
break;
series[count]="3"+series[i];
count++;
startIndex++;
}
startIndex=index;
for(int i=startIndex;i<last;i++){
if(count>=n)
break;
series[count]="4"+series[i];
count++;
startIndex++;
}
}
Integer[] intSeries= new Integer[series.length];
for(int i=0;i<series.length;i++){
intSeries[i]=Integer.valueOf(series[i]);
}
return intSeries;
}
}

Posted On : 2017-08-08 20:57:01
Satisfied : 0 Yes  0 No
profile Rishi Kumar - anyforum.in Rishi Kumar
523187021168
Reply This Thread
up-rate
0
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in