Generation

generate functionTue, 24 Jan 2023

Two integer values on standard input. Input x(1<x<10) and n(1≤n≤100). A program that prints to the standard output the smallest integer whose power of x (xk,k>0) exceeds n digits.

import java.util.Scanner; class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int x = sc.nextInt(); int n = sc.nextInt(); int y = 1; int i = 0; while(true){ y = (int)Math.pow(x, i); if(String.valueOf(y).length() == n){ System.out.println(y); break; } i++; } } }

Questions about programming?Chat with your personal AI assistant