1. Engineering
  2. Computer Science
  3. modify the following given java program you are expected to...

Question: modify the following given java program you are expected to...

Question details

Modify the following given Java program. You are expected to modify the supplied Exercise1.java to print just the last lines of each paragraph in HTML format. Copy and paste the Sample input on the console then print the Expected output.

import java.util.Scanner;

public class Exercise1 {
/** A simple static string for HTML & table header. */
private static final String HTMLHeader =
"<!DOCTYPE html>\n"
+ " <html>\n"
+ " <head>\n"
+ " <title>CSE: Exercise 1</title>\n"
+ " </head>\n"
+ " <body>\n"
+ " <table border=1>";
  
/** A simple static string to print HMTL footer. */
private static final String HTMLFooter =
" </table>\n"
+ " </body>\n"
+ "</html>

public static void main(String[] args) {
System.out.println(HTMLHeader);
Scanner keyboard = new Scanner(System.in);

while (keyboard.hasNextLine()) {
String line = keyboard.nextLine();
System.out.println(" <tr><td>" + line + "</td></tr>");
}
System.out.println(HTMLFooter);
}
}

Sample input:

para #1

welcome.

para #2: Introduction

This is a simple test line

to create a 2 line para

conclusion of inputs

This para is the last para.

It has 3 lines

3 lines including this one and 3 blank lines at end

Last paragraph with 1 line

Expected output:

<!DOCTYPE html>

<html>

<head>

<title>CSE: Exercise 1</title>

</head>

<body>

<table border=1>

<tr><td>welcome. </td></tr>

<tr><td>to create a 2 line para</td></tr>

<tr><td>3 lines including this one and 3 blank lines at end</td></tr>

<tr><td>Last paragraph with 1 line</td></tr>

</table>

</body>

</html>

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution