Computer Science, asked by ktr1705, 3 months ago

What is the java program to print series of 1 + 2^2/2 + 3^3/3 + 4^4/4...+ n^n/n

Answers

Answered by Anonymous
0

Answer:Let us assume the question is to calculate sum = 1/2 + 2/3 + 3/4 + … + n/(n+1), then we can use the main program’s argument to pass the value of n in. No special library or class is needed to import in this example.

public static void main(String[ ] args) {  

       if (args.length  == 0) {  

           System.out.println("Please give n.");  

           return;  

       }  

       int n = Integer.parseInt(args[0]);  

       double s = 0;  

       for(int i=1; i<=n; i++) {  

           s += (i * 1.0) / (i + 1.0);  

       }  

       System.out.println("Sum = " + s);  

   }

Similar questions