Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
Dr. Martin Goik
GoikLectures
Commits
bf397d35
Commit
bf397d35
authored
Sep 20, 2020
by
Dr. Martin Goik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
HTML table using multiline statements
parent
a1a7509b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
63 additions
and
32 deletions
+63
-32
Doc/Sd1/statements.xml
Doc/Sd1/statements.xml
+63
-32
No files found.
Doc/Sd1/statements.xml
View file @
bf397d35
...
...
@@ -3997,11 +3997,25 @@ System.out.format("Start:<emphasis role="red">%5d</emphasis>:End", <emphasis
<qandaentry>
<question>
<para>
Modify the previous code to generate HTML output instead
of pure text and watch the result in a web browser:
</para>
of pure text and watch the result using a web browser. The
expected output reads:
</para>
<programlisting
language=
"xml"
>
<
html xmlns='http://www.w3.org/1999/xhtml'
>
<
head
>
<
title
>
A square table
<
/title
>
<
title
>
A square table
<
/title
>
<
!-- CSS based styling --
>
<
style
>
table,td,th {
border: 1px solid black;
}
table {
border-collapse: collapse;
}
td {
text-align: right;
}
<
/style
>
<
/head
>
<
body
>
<
table
>
...
...
@@ -4009,13 +4023,16 @@ System.out.format("Start:<emphasis role="red">%5d</emphasis>:End", <emphasis
<
th
>
n
<
/th
><
th
>
n * n
<
/th
>
<
/tr
>
<
tr
>
<
td style='text-align: right;'
>
0
<
/td
><
td style='text-align: right;'
>
0
<
/td
>
<
td
>
<emphasis
role=
"red"
>
0
</emphasis>
<
/td
><
td
>
<emphasis
role=
"red"
>
0
</emphasis>
<
/td
>
<
/tr
>
<
tr
>
<
td style='text-align: right;'
>
1
<
/td
><
td style='text-align: right;'
>
1
<
/td
>
<
td
>
<emphasis
role=
"red"
>
1
</emphasis>
<
/td
><
td
>
<emphasis
role=
"red"
>
1
</emphasis>
<
/td
>
<
/tr
>
<
tr
>
<
td style='text-align: right;'
>
2
<
/td
><
td style='text-align: right;'
>
4
<
/td
>
<
td
>
<emphasis
role=
"red"
>
2
</emphasis>
<
/td
><
td
>
<emphasis
role=
"red"
>
4
</emphasis>
<
/td
>
<
/tr
>
...
<
/table
>
...
...
@@ -4025,34 +4042,48 @@ System.out.format("Start:<emphasis role="red">%5d</emphasis>:End", <emphasis
<answer>
<programlisting
language=
"java"
>
public static void main(String[] args) {
final int LIMIT = 20; // The number of records to be printed
System.out.print(
"" + "
<
html xmlns='http://www.w3.org/1999/xhtml'
>
\n"
+ "
<
head
>
\n"
+ "
<
title
>
A square table
<
/title
>
\n"
+ "
<
/head
>
\n"
+ "
<
body
>
\n"
+ "
<
table
>
\n");
System.out.println("
<
tr
>
");
System.out.println("
<
th
>
n
<
/th
><
th
>
n * n
<
/th
>
");
System.out.println("
<
/tr
>
");
for (int i = 0; i
<
= LIMIT; i++) { // Printing the table's body
System.out.println("
<
tr
>
");
System.out.println("
<
td style='text-align: right;'
>
" + i +
"
<
/td
><
td style='text-align: right;'
>
" + i * i + "
<
/td
>
");
System.out.println("
<
/tr
>
");
final int LIMIT = 20; // The number of records to be printed
System.out.print("""
<
html xmlns='http://www.w3.org/1999/xhtml'
>
<
head
>
<
title
>
A square table
<
/title
>
<
!-- CSS based styling --
>
<
style
>
table,td,th {
border: 1px solid black;
}
table {
border-collapse: collapse;
}
td {
text-align: right;
}
<
/style
>
<
/head
>
<
body
>
<
table
>
<
tr
>
<
th
>
n
<
/th
><
th
>
n * n
<
/th
>
<
/tr
>
""");
final int trBlockIndent = 6; // Each
<
tr
>
...
<
/tr
>
is being indented by 6 spaces
for (int i = 0; i
<
= LIMIT; i++) { // Printing the table's body
System.out.print(("""
<
tr
>
<
td
>
""" + i + "
<
/td
>
").indent(trBlockIndent));
System.out.print(("""
<
td
>
""" + i * i + "
<
/td
>
").indent(trBlockIndent));
System.out.print("""
<
/tr
>
""".indent(trBlockIndent));
}
System.out.print(
"" + "
<
/table
>
\n"
+ "
<
/body
>
\n"
+ "
<
/html
>
\n
");
System.out.print(
"""
<
/table
>
<
/body
>
<
/html
>
""
");
}
</programlisting>
</answer>
</qandaentry>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment