Complete the program below. The program takes in two positive integers, n and m, and should print out all the powers of n that are less than or equal to m, on seperate lines. Assume both n and m are positive with n less than or equal to m.
For example, if the input values are n = 2 and m = 40 the output should be:
2
4
8
16
32
Starter code:
import java.util.Scanner;
public class Powers {
public static void main(String[] args) {
//get the input integers n and m
Scanner scnr = new Scanner(System.in);
int n = scnr.nextInt();
int m = scnr.nextInt();
//print out the powers of n that are less than or equal to m
//TODO: complete the program
}
}
import java.util.Scanner; public class Powers { public static void main(String[] args) { //get the input integers n and m Scanner scnr = new Scanner(System.in); int n = scnr.nextInt(); int m = scnr.nextInt(); int result = n; while(result<=m){ System.out.println(result); result = result * n; } } }
Get Answers For Free
Most questions answered within 1 hours.