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.
- Practice
- Java
- Introduction
- Java Loops II
- Discussions
Java Loops II
Java Loops II
sauravdx007 + 0 comments I am not getting the question., Can anyone please explain what I need to do?
steveperkins + 0 comments This is an absolute joke. My code worked on the first try, but the exercise was:
5% - Demonstrating the ability to write a two-level nested "for" loop in Java.
95% - Getting your mind back into the mode of undergraduate algebra, and deciphering this ridiciously contrived number series.
For this website to have any meaningful value at all, that emphasis should really be the reverse.
sharmatushar124 + 0 comments Guys, done without creating another object please checkout
class Solution{ 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(); for(int j = 0; j < n; j++){ a = a + (int)Math.pow(2,j)*b; System.out.print(a + " "); } System.out.println(""); } in.close(); } }
RodneyShag + 0 comments Java solution - passes 100% of test cases
If using Math.pow(), make sure you cast it to an integer since it returns a double.
import java.util.Scanner; class Solution{ public static void main(String [] args) { Scanner scan = new Scanner(System.in); int t = scan.nextInt(); for (int i = 0; i < t; i++) { int a = scan.nextInt(); int b = scan.nextInt(); int n = scan.nextInt(); for (int j = 0; j < n; j++) { a += b * (int) Math.pow(2, j); System.out.print(a + " "); } System.out.println(); } scan.close(); } }
From my HackerRank Java solutions.
faizjaved + 0 comments class Solution{ public static void main(String []argh){ Scanner in = new Scanner(System.in); int q=in.nextInt(); for(int i=0;i<q;i++){ int a = in.nextInt(); int b = in.nextInt(); int n = in.nextInt(); for(int j=0;j<n;j++) { a+=b; System.out.print(a + " "); b*=2; } System.out.println(); } in.close(); } }
Load more conversations
Sort 2105 Discussions, By:
Please Login in order to post a comment