Home > database >  for loop java increments
for loop java increments

Time:08-24

I'm trying to do a math equation increment.

I'm starting at 2,500. After the equation solves for a, x3 becomes 2,800. I need a to replace 2,500 with 2,800 so I can get the next answer 3,136. After 3,136 it should be 3512.32 and so forth.. I don't know how to do the loop for this..

essentially it'll increment more than 300 after a few loops, but yes. basically like 50 ^ 3 = 125,00. which is 50 * 50 * 50. First it's 2500, then 2800, 3136, 3512, and then next is 3933, 4404, and so forth. That's 5 loops. I want to be able to do up to 100 loops.

public class Formula {

public static void main(String[] args) {
    
    double a = 2500;
    
    double x1 = 0;
    double x2 = 0;
    double x3 = 0;
    
    x1 = a / 2.5;
    x2 = ((x1 * 1.3)   (x1 * 1.5));
    x3 = x2;
    
    
        System.out.println(x3);
    }
}

CodePudding user response:

Try this:

for (int i = 0; i < 100; i  ) {
    double a = 2500   i * 300;
    a = a / 2.5;
    a = ((a * 1.3)   (a * 1.5));
    System.out.println(a);
}

Unnecessary variables removed.

CodePudding user response:

public static void main(String[] args) { Scanner kboard = new Scanner(System.in);

    double a = 2500;
    int y;
    double x1 = 0;
    double x2 = 0;
    double x3 = 0;

    System.out.println("enter amount of repetitions");
    y = kboard.nextInt();

    for( int i = 0; i<y; y  ){

        x1 = a / 2.5;
        x2 = ((x1 * 1.3)   (x1 * 1.5));
        x3 = x2;
        x3= a;
    }
    System.out.println(x3);
}

CodePudding user response:

I combined both Oscar Rautianinen and Bohemian answers and made it into one code and it turned out almost what I needed! Only thing I can't figure out is if I wanted it to loop only 10 times. Instead, I have to put the "final" answer and it would give me my starting number up until the "final" answer of 10000. So if anyone knows how to fix that. Please answer/comment! Thank you

  • Related