Filled Blanks

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   hear noise   go to next page

Answer:

See below

Filled Blanks

The blanks can easily be filled with a little typing aided by copy and paste from other parts of the program.

import java.io.*;
import java.util.Scanner;

class AddDoubles
{
  public static void main (String[] args)
  {
    double first, second, sum;
    Scanner scan = new Scanner( System.in );
 
    // Read in the first double
    System.out.print("Enter the first double: ");
    first = scan.nextDouble();

    // Read in the second double
    System.out.print("Enter the second double: ");
    second = scan.nextDouble();

    // Compute the sum and write it out
    sum = first + second;
    System.out.print("Sum: " + sum );
  }
}

Here is a run of the program:

C:/temp>java AddDoubles
Enter the first double: 10.59
Enter the second double: 8.02
Sum: 18.61

QUESTION 7:

(Thought Question: ) Could the variable sum be eliminated from this program?