We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
public int display(int n,int i){
int mul;
if(i == 0) {
mul = 1;
return mul;
}else if(i == 1) {
mul = 2;
return mul;
}else{
mul = n * 2;
return mul;
}
}
public static void main(String []argh){
Scanner in = new Scanner(System.in);
int t = in.nextInt();
for(int i = 0;i < t; i++){
int a = in.nextInt();
int b = in.nextInt();
int n = in.nextInt();
int total;
int l = 2;
Solution x = new Solution();
for(int j = 0; j < n; j++){
int m = x.display(l,j);
total = a + m * b;
System.out.printf("%d ",total);
a = total;
l = m;
}
System.out.println("");
}
}
}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Java Loops II
You are viewing a single comment's thread. Return to all comments →
class Solution{
}