import java.lang.*; import java.io.*; import java.util.*; public class Tank { public static void main(String[] args) throws IOException{ //test program BufferedReader buf = new BufferedReader(new InputStreamReader(System.in)); Random random = new Random(0); int c=0; //counter int x=(int)((random.nextDouble()*1000)+1); //target tank while(true){ c++; System.out.println("Target at "+x+"m"); System.out.print("Input Angle(0 - Pi/2):"); double a = Double.parseDouble(buf.readLine()); System.out.print("Input Speed(m/s):"); double s = Double.parseDouble(buf.readLine()); double d = (s * s * Math.sin( 2 * a ))/9.8 ; System.out.println("Distance = "+d+" m"); if(d > (x-10) && d < (x+10)) break; //move target tank x=(int)((random.nextDouble()*1000)+1); } System.out.println("HIT!"); System.out.println(c+" turns to hit"); } }