For any two strings of digits,A and B, we define Fa,b to be the sequence (A,B ,AB ,BAB ,ABBAB ,...) in which each term is the concatenation of the previous two.
Further, we define Da,b(n) to be the n-th digit in the first term of Fa,b that contains at least
n digits.
Example:
Let A=1415926535 ,B=8979323846 . We wish to find Da,b(35)
, say.
The first few terms of Fa,b are:
1415926535 8979323846 141592653589793233846 897932384614159265358979323846 14159265358979323846897932384614159265358979323846
Then Da,b(35) is the 35-th digit in the fifth term, which is
9.
You are given q triples (A,B,n). For all of them find
Da,b(n).
Input Format
First line of each test file contains a single integer q that is the number of triples. Then q lines follow, each containing two strings of decimal digits a and b and positive integer n.
Output Format
Print exactly q lines with a single decimal digit on each: value of Da,b(n) for the corresponding triple.
public void fibo(String a,String b,int n){
String n1=Integer.toString(n);
char n2;
n2=n1.charAt(1);
int n3=Character.getNumericValue(n2);
String c;
for(int i=2;i<n3;i++){
c=a+b;
System.out.printf(c+" ");
a=b;
b=c;
}
System.out.println(c.charAt(n));
}
Compile Message
Solution.java:26: error: variable c might not have been initialized System.out.println(c.charAt(n)); ^ 1 error
Exit Status
1