by Dinesh Thakur Category: Introduction to Java

In this Example we Reading amount, Year and interest in the class Scanner becomes analogous to reading string. In this example, the three numbers are read from the console, and then perform Simple Interest,Compound Interest operations and results printed on the screen in formatted output.

 import java.util .*;
class InputDemo
{
            public static void main (String args [ ])
       {
            double p, n, r,si,ci;
            Scanner s=new Scanner (System. in);
            System.out.println("Enter the amount:");
            p=s.nextDouble( );
            System. out. println("Enter the No.of years:");
            n=s.nextDouble( );
            System. out. println("Enter the Rate of  interest");
            r=s.nextDouble( );
            si=(p*n*r)/100;
            ci=p*Math.pow(1.0+r/100.0,n)-p;
            System.out. println(" Amount="+p );
            System. out. println("N o. of years="+n);
            System. out. println("Rate of interest="+r);
            System.out.println("Simple Interest="+si);
            System.out. println("Compound Interest="+ci);
           }
}


About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.



Search Content