Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

My code works but I have a problem on where I need to put the newline. 7 8 12 1 import java.util.Scanner; 2 import java.io.;

My code works but I have a problem on where I need to put the newline.
image text in transcribed
image text in transcribed
7 8 12 1 import java.util.Scanner; 2 import java.io."; 3 import java.io.IOException; 4 public class LabProgram { 5 public static void main(String args) { 6 Scanner scnr - new Scanner(System.in); String filename - scnr.next(); // get the filename from user try{ // try 9 // open the file 10 FileInputStrean fs = new FileInputStream(new File(filename)); 11 while(true) { // keep looping String str ""; // string initialized with empty string 13 int ch; 14 while((ch-fs.read() != -1){ 15 if(ch - ' ')break; // if '' that means end of 16 (char)ch; // otherwise add the character to 17 I replace the photo.jpg to info.txt Systen.out.println(str.replace("-photo.jpg","info, txt >> if(ch-1)break; } 22 fs.close(: 23 }catch (IOException e) { e.printStackTrace(): 25 26 } 27 scar.closeO: 28 29) 30) 31 str. 18 19 20 21 24 Special character legend Output is nearly correct, but whitespace differs. See highlights below. Input Parkphotos.txt Acadia2003_info.txt AmericanSamoa1989_info.txt BlackCanyonoftheGunnison1983_info.txt CarlsbadCaverns 2010_info.txt Craterlake1996_info.txt GrandCanyon1996_info.txt Indiana Dunes1987_info.txt LakeClark2009_info.txt Redwood1980_info.txt Virgin Islands 2007_info.txt Voyageurs 2006_info.txt Wrangellstelias1987 info.txt Your output Expected output Acadia2003 info.txt American Samoa1989_info.txt BlackCanyonoftheGunnison 1983_info.txt CarlsbadCaverns 2010_info.txt Craterlake1996 info.txt GrandCanyon 1996 info.txt IndianaDunes1987 info.txt Lakeclark2009 into.txt Redwood1980 info.txt Virgin Islands 2007 info.txt Voyageurs 2006 info.txt Wrangellstelias 1987 info.txt

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

Fundamentals Of Database Systems

Authors: Sham Navathe,Ramez Elmasri

5th Edition

B01FGJTE0Q, 978-0805317558

More Books

Students also viewed these Databases questions