import java.lang.*; import java.io.*; import java.util.*; //Random search canon bombardment public class Canon1 { public static void main(String[] args){ Random rand = new Random(0); //Set random seed int counter = 0; //Initialize counter System.out.println("Target at 500m"); System.out.println("Angle, Speed, Distance"); while(true){ //Main Loop counter++; double angle = rand.nextDouble()*(Math.PI/2.0); double speed = rand.nextDouble()*(100); double distance = (speed * speed * Math.sin( angle * 2.0 ))/9.8 ; System.out.println(angle+", "+speed+", "+distance); if(distance > 490 && distance < 510) break; //if hit then exit loop }//end Main Loop System.out.println(counter+" turns to hit"); }//end main() }//end class Canon1