Find Us On:

# Java - Lab 10: Text Files

flamenca91

Exercise 1 1. Create a New Project named TextFileExample. 2. Declare and instantiate a two-dimensional int array called temperatures which contains four rows (corresponding to weeks) and seven columns (corresponding to days). Read the temperature data from a file called TemperatureData.txt that you will download from Blackboard. Write a nested for loop that prints out the values of the temperature data. The output will appear as follows: Temperature Data Week 1: 73 71 68 69 75 77 78 Week 2: 76 73 72 72 75 79 76 Week 3: 79 82 84 84 81 78 78 Week 4: 75 72 68 69 65 63 65 Attachments
Tags Clarifications

## Java - Temperature Data - Solution

dickersonka

Attached is the solution to the Java - Temperature Data assignment including source and comments Attachments
Preview
= 0; week < temps.length; week++){ //loop through days for(int day = 0; day<temps[week].length; day++){ //set value in array temps[week][day] = fileReader.nextInt(); } } //loop through weeks for(int week = 0; week < temps.length; week++){ //display week

Preview
69 75 77 78 76 73 72 72

Screenshots

## Solution

mariobeka

Below you will find the TextFileExample class and the .txt file I used to make the solution. A screenshot of the executed program is also provided. Attachments
TextFileExample.java (1 K) Preview
{ for (int i = 0; i < 4; i++) { counter = counter + 1; for (int m = 0; m < 7; m++) { temperatures[i][m] = scan.nextInt(); } } } // Print the weeks for (int i = 0; i < 4; i++) { System.out.println("Week " +

TemperatureData.txt (1 K)
Screen Shot 2014-04-29 at 12.31.40 AM.png (22 K) Preview

Screenshots