Hello I'm begining to learn Java and I'm trying to convert from a While loop into a for loop. Sadly I'm just not quite grasping it...
I understand the loop is here
while (n * n > Math.pow(2,i))
{
i++;
}
but it's not quite as simple as changing the while to a for either...
import javax.swing.JOptionPane;
public class Main_Class_WhileLoop {
public static void main(String[] args)
{;
String input = JOptionPane.showInputDialog(
"Please enter a number, 0 to quit:");
int n = Integer.parseInt(input);
int i = 1;
while (n * n > Math.pow(2,i))
{
i++;
}
System.out.println("2 raised to " + i
+ " is the first power of two greater than " + n + " squared");
}
}