how to do 10 ^0. 10^1 …etc powers on codng
my code :
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int ans = 0;
while (n != 0) {
n = n / 8;
int rem = 8 - n;
ans = ans + rem * 10;
}
System.out.println(ans);
how to do 10 ^0. 10^1 …etc powers on codng
my code :
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int ans = 0;
while (n != 0) {
n = n / 8;
int rem = 8 - n;
ans = ans + rem * 10;
}
System.out.println(ans);
Hi nipun,
In this case make 1 variable power and initialize it with 1. Then in each iteration multiply power with 10.
ok thanks i got the idea