Search for more details......

For loops for calculations(Graphing tables)

You can write a program easily that fills all of columns in a table or other like that.

You must  have a function for it or you have to create it in the correct for

For example you want to evaluate y=x^2  1<x<81


public class Ex{

     public static void main(String args[]){


           double y=0; //Define y variable


           for(int x=1;x<=80;x++){ //For loop to go to each x value.


               y=Math.pow(x,2); // Evaluate function.


              System.out.println(x+"^2="+y); //Print it out to console. If you don't want decimal point cast y to int. (int)y.


           }




    }

}


No comments:

Post a Comment