Code example for Scanner

Methods: nextDoublenextInt

0
 * @author springtree 
 */ 
import java.util.Scanner; 
public class Q2_15 { 
    public static void main (String[] args) {
        Scanner input = new Scanner(System.in);
         
        System.out.println ("Enter annual rate: ");
        double annualRate = input.nextDouble();
        double monthlyRate = annualRate / 12;
         
        System.out.println ("Enter months: ");
        int months = input.nextInt();
         
        double sum1 = 100 + 100 * (1 + monthlyRate);
        double sum2 = (sum1 + 100) * (1 + monthlyRate);
        double sum3 = (sum2 + 100) * (1 + monthlyRate);
        double sum4 = (sum3 + 100) * (1 + monthlyRate);
        double sum5 = (sum4 + 100) * (1 + monthlyRate);
        double sum6 = (sum5 + 100) * (1 + monthlyRate);
Experience pair programming with AI  Get Codota for Java