Results 1 to 2 of 2
  1. #1
    mcgillstudent is offline Member
    Join Date
    Jan 2013
    Posts
    5
    Rep Power
    0

    Default How to: Create a range of desired variables (two decimals) into an array

    Hi everyone,

    I'm curious how I can create a range of desired variables ranging from (-1.00 all the way to 1.00) @ 0.01 increments.

    I will want to output this in table format as the first column. There will be 4 columns btw

    1st column = the variable [two decimals btw -1.00 and 1.00]
    2nd column = math.sin(x) of each
    3rd column = my personal sin function
    4th column = math.abs(difference between them)

    Java Code:
    public class TaylorSin {
    	public static void main(String[] args) {
    	for (double lB = -100, lB <= 100,lB++) lB.log(x/100);
    	double[] x = lB;     
    	double ActualFormula = math.sin(x);
    	double MyFormula = sin(x);
    	double Absolute = math.abs(ActualFormula - MyFormula);
    	System.out.format("%3d%10d%10d%4d", double x, ActualFormula, MyFormula, Absolute);
    I'm calling my other personally created sin(x) method and attemping to output in table format.

    Let me know, because I'm very confused.
    Last edited by mcgillstudent; 03-05-2013 at 07:47 PM.

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    United States
    Posts
    703
    Rep Power
    1

    Default Re: How to: Create a range of desired variables (two decimals) into an array

    Your for loop only has a single statement in it. And it doesn't do anything unless you are changing something in IB.log(). But even then, x is undefined.

    To increment your value by .01 in your for loop just use IB = IB + .01 (or shorthand IB += .01)

    Regards,
    Jim
    The Java™ Tutorial
    YAT -- Yet Another Typo

Similar Threads

  1. apply an array to variables
    By Stamoulohta in forum New To Java
    Replies: 5
    Last Post: 03-16-2011, 12:27 PM
  2. Array index out of range: 1 HELP!
    By TheBreadCat in forum New To Java
    Replies: 2
    Last Post: 02-17-2011, 08:50 PM
  3. Range within an Array
    By End in forum New To Java
    Replies: 6
    Last Post: 04-18-2009, 06:53 PM
  4. Replies: 3
    Last Post: 08-24-2008, 01:51 PM
  5. how to create environment variables
    By elizabeth in forum Advanced Java
    Replies: 4
    Last Post: 08-02-2007, 04:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •