Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The purpose of this lab is to give you experience in using an input file and then uploading your project to canvas. Create a project

The purpose of this lab is to give you experience in using an input file and then uploading your project to canvas.

Create a project called L4a.

Use the input file called circles.in, which consists of some doubles (not integers).

In your program, input all these numbers, print them, and then calculate and output their sum. Output to the screen.

4.9 1.3 2.5 1.1 2.5 5.1 3.8 2.6 6.0 3.6 3.3 4.2 2.9 3.8 2.2

This is what i have so far I keep getting an error

public class L4a {

public static void main(String[] args) {

File inFile = new File("circles.in"); Scanner Scnr = null; try{ Scnr = new Scanner(inFile); } catch(Exception e){ System.out.println("Error. File not found."); } Scanner user= new Scanner(System.in); int count=0; double sum = 0; double num = fileInput.next(); while(Scnr.hasNext()) { sum = sum + num; num = Scnr.nextDouble(); } System.out.println("Sum of all numbers = " + sum); } }

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_2

Step: 3

blur-text-image_3

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

Database Reliability Engineering Designing And Operating Resilient Database Systems

Authors: Laine Campbell, Charity Majors

1st Edition

978-1491925942

More Books

Students also viewed these Databases questions