Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GoikLectures
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Goik Martin
GoikLectures
Commits
e85b3b4e
Commit
e85b3b4e
authored
9 years ago
by
Goik Martin
Browse files
Options
Downloads
Patches
Plain Diff
Cosmetics
parent
1f8640cb
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Doc/Sd1/coreClasses.xml
+9
-31
9 additions, 31 deletions
Doc/Sd1/coreClasses.xml
with
9 additions
and
31 deletions
Doc/Sd1/coreClasses.xml
+
9
−
31
View file @
e85b3b4e
...
...
@@ -334,7 +334,7 @@ public class CircleAreaCalculator {
<para>
Representing the above string in a
<xref
linkend=
"glo_Java"
/>
program may be cumbersome due to its
excessive length discouraging a single line representation.
You may favor
decomposing it to a set of
smaller string
You may favor
assembling it from
smaller string
literals:
</para>
<programlisting
language=
"java"
>
final String input = "731671765 ... 94934"
...
...
@@ -446,29 +446,6 @@ public class CircleAreaCalculator {
}
}
</programlisting>
<para>
Remark: Since both Unicode and
<xref
linkend=
"glo_ASCII"
/>
represent digits by 10 successive integer values we may as well
choose the following implementation:
</para>
<programlisting
language=
"java"
>
private static int getDigitValue (final char digit) {
switch(digit) {
case '0': return 0;
case '1': return 1;
case '2': return 2;
case '3': return 3;
case '4': return 4;
case '5': return 5;
case '6': return 6;
case '7': return 7;
case '8': return 8;
case '9': return 9;
default:
System.err.println("Character '" + digit + "' is no digit, exiting");
System.exit(1);
return 0;
}
}
</programlisting>
<para>
Next we must compute a given string's product of digits.
Taking the first value
<code>
7316717653133
</code>
from above we
are looking for 7 × 3 ×1 × 6 ×7 × 1 ×7 × 6 × 5 × 3 × 1 × 3 × 3 =
...
...
@@ -509,7 +486,7 @@ public class CircleAreaCalculator {
return product;
}
</programlisting>
<para>
Putt
ing these pieces
together
leaves us with the following
<para>
Assembl
ing these pieces leaves us with the following
<code>
main(...)
</code>
method:
</para>
<programlisting
language=
"java"
>
public static void main(String[] args) {
...
...
@@ -540,16 +517,17 @@ public class CircleAreaCalculator {
final int numOfDigits = 13; // The intended number of adjacent digits
long maximumDigitProduct = 0;
String maxDigitString = null;
for (int i = 0; i
<
input.length() - numOfDigits + 1; i++) {
final String
fourD
igitWord = input.substring(i, i + numOfDigits);
final long productOfDigits = getDigitProduct(
fourD
igitWord);
final String
d
igitWord = input.substring(i, i + numOfDigits);
final long productOfDigits = getDigitProduct(
d
igitWord);
if (maximumDigitProduct
<
productOfDigits) {
maximumDigitProduct = productOfDigits;
maxDigitString = digitWord;
}
}
System.out.println("The
largest product of " + numOfDigits + " digits in
succession is " + maximumDigitProduct
+ ".");
System.out.println("The
substring '" + maxDigitString +
"' yields the largest product value " + getDigitProduct(maxDigitString)
+ ".");
}
</programlisting>
<para>
The largest product of 13 successive digits stems from the
...
...
@@ -558,7 +536,7 @@ public class CircleAreaCalculator {
digits in the fourth definition line of
<code>
String input =
...
</code>
.
</para>
<programlisting
language=
"none"
>
The
largest product of 13 digits in succession is
23514624000.
</programlisting>
<programlisting
language=
"none"
>
The
substring '5576689664895' yields the largest product value
23514624000.
</programlisting>
</answer>
</qandaentry>
</qandadiv>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment