A
A
Alexander Sharomet2015-05-22 09:40:42
Java
Alexander Sharomet, 2015-05-22 09:40:42

How to solve similar equation using java?

Hello.
How can you solve this equation using java?
939693aca24a41698c0ee68fc2018f78.png
Here is an example of how I tried to solve it, but I suspect that this is not true.

import java.util.Scanner;
public class MYClass {
  public static void main(String []args){
    int n,k;
    
    Scanner sc = new Scanner(System.in);
    
    System.out.println("Введите число N: ");
    n=sc.nextInt();
    
    System.out.println("Введите число K: ");
    k=sc.nextInt();
    
    
    for(int i=1;i<n;i++){
      for(int j=1;j<k;j++){
        System.out.println((j+3)/(i+Math.pow(j,2)));
      }
    }
    
  }
}

Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2015-05-22
@sharomet

Instead of displaying to the screen, you need to store the value in a variable and add a new value to it on each iteration of the loop

double sum = 0;
for(int i=1;i<n;i++){
      for(int j=1;j<k;j++){
        double divider = i+Math.pow(j,2);
        if( divider != 0 )
            sum+=(j+3)/divider;
        else
            // обработать ошибку
      }
}

Something like this :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question