Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The reciprocal of widthInput is 1 / widthInput. The following program intends to read a floating - point value from input, compute the reciprocal of

The reciprocal of widthInput is 1/ widthInput. The following program intends to read a floating-point value from input, compute the reciprocal of the value, and output the reciprocal, but the code contains three errors. Find and fix all three errors.
Ex: If the input is 0.360, then the output is:
The reciprocal of width =1/0.360=2.778
import java.util.Scanner;
public class WidthReciprocal {
public static void main(String[] args){
Scanner scnr = new Scanner(System.in);
// Modify the following code
int widthInput;
int reciprocalVal;
widthInput = scnr.nextInt();
reciprocalVal =1/ widthInput;
System.out.printf("The reciprocal of width =1/%.3f", widthInput);
System.out.printf("=%.3f
", reciprocalVal);
}
}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems Iv Special Issue On Database Systems For Biomedical Applications Lncs 6990

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Christian Bohm ,Johann Eder ,Claudia Plant

2011th Edition

3642237398, 978-3642237393

More Books

Students also viewed these Databases questions

Question

=+7. What lifestyle traits does your key public have?

Answered: 1 week ago