Search This Blog

If you like any posts in this blog then click this icon which is present under the post

Friday, 1 July 2011

Program for Type Conversion in Java

import java.io.*;
class Typeconversion
{
    public static void main(String args[])
    {
        double i;
        float sum1=0.0f,sum=0.0f;
        for(i=1;i<=20;i++)
        {
            sum1=(float)i;
            sum+=(1/sum1);

          
        }
        i--;
        System.out.println("I = "+i+"numbers");
       
        System.out.println("Sum of (1/I) = "+sum);

    }
}

Output

I = 20.0numbers

Sum of (1/I) = 3.5977397

No comments:

Post a Comment

Followers