Write a program to find the sum of 1/2+4/3+5/6+8/7+9/10 using loop in java

 


Write a program to find the sum of 1/2+4/3+5/6+8/7+9/10 using loop in java

public class SumOfSeries
{
   public static void main(String args[]){
       double a=1,b=2,sum=0;
    for(double i=1;i<=5;i++){
        if(i%2!=0){
         System.out.print(a+"/"+b+" + ");
            sum+=a/b;
            a=a+2;
            b=b+2;
        }else{
        
         System.out.print(b+"/"+a+" + ");
            sum+=b/a;
         a=a+2;
         b=b+2;
        }
    }
    System.out.println(" = "+sum);
    }
}

Output
1.0/2.0 + 4.0/3.0 + 5.0/6.0 + 8.0/7.0 + 9.0/10.0 + = 4.70952380952381

Comments

Popular posts from this blog

How to make simple bill maker by using python tkinter

Make a GST Calculator using HTML and JavaScript