Question: Assume file input.txt contains the text shown in the box below: Roses are red, Violets are blue, Sugar is sweet, But I have commitment issues.

Assume file input.txt contains the text shown in the box below:

Roses are red, Violets are blue, Sugar is sweet, But I have commitment issues. So I'd rather just be friends at this point in our relationship.

Trace the following program and write down the exact output as it would appear on the screen.

import java.util.Scanner; import java.io.*;

public class Test1 {

public static void main (String[] args)throws FileNotFoundException {

Scanner input = new Scanner(new File("input.txt"));

while (input.hasNextLine()) { String s = input.nextLine();

Scanner lineScan = new Scanner(s);

int y = 0;

while (lineScan.hasNext()) {

String x = lineScan.next();

y++;

}

System.out.println(y);

}

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!