Question (school):
Write a program that prompts for two numbers, then divides the first by the second. Write the answer in the form "<a> divided by <b> is <answer>."
My Code:
import java.io.*; //this needs to be at the top of your program, right below the “packages” /** * @author: My Name * @date: 2013-09-27 * @filename: ICS3UMyNameJavaAssignment2d.java * @description: Asks the user for 2 numbers than divides the first number by the second. */ public class ICS3UMyNameJavaAssignment2d { public static void main (String[] args) throws Exception { { BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in)); String f; //creates a string variable to get first number from user double first = 0.0; //double first needed later System.out.print("Enter the first number: "); //gets first number from user f = buffer.readLine(); //reads a line from the console first = Double.parseDouble(f);//gets the double value from string variable f System.out.println(f + " will be divided by: "); //states string variable f String s; //creates a string variable to get time (travelled) from user double second = 0.0; //double second System.out.print("Enter the second number: "); //gets the second number from user s = buffer.readLine(); //reads a line from the console second = Double.parseDouble(s);//gets the double value from string variable s System.out.println("The quotient of " + f + " and " + s + " is " + f/s); //output } } }
Error: