Donate. I desperately need donations to survive due to my health

Get paid by answering surveys Click here

Click here to donate

Remote/Work from Home jobs

How to get data type to be accessible across methods?

import java.util.Scanner;
public class Homework5
{
   public static void main(String[] agrs)
   {
      double g = 9.8;
      int t;
      System.out.println("The output is");
      for(t = 1; t<=10; t++)
      {
         fallingDistance(.5*g*t*t);
      }


    }
   public static void fallingDistance(double distance)
   {

      System.out.println("The distance for " + t + "seconds is " + distance);

   }



}

How would I be able to use the variable "t" used in the for loop, to be accessable outside of it, as well as in the fallingDistance method? Thanks!

Comments