Lab11
This commit is contained in:
parent
bf56587261
commit
4b777cc8dd
2
.gitignore
vendored
2
.gitignore
vendored
@ -16,3 +16,5 @@
|
|||||||
/Assignments/Lab10_CalebFontenot/build/
|
/Assignments/Lab10_CalebFontenot/build/
|
||||||
/Assignments/InClassOct6th/nbproject/private/
|
/Assignments/InClassOct6th/nbproject/private/
|
||||||
/Assignments/InClassOct6th/build/
|
/Assignments/InClassOct6th/build/
|
||||||
|
/Assignments/lab11_CalebFontenot/nbproject/private/
|
||||||
|
/Assignments/lab11_CalebFontenot/build/
|
||||||
|
46
Assignments/lab11_CalebFontenot/DoWhile1.html
Normal file
46
Assignments/lab11_CalebFontenot/DoWhile1.html
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>DoWhile1.java</title>
|
||||||
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||||
|
<style type="text/css">
|
||||||
|
<!--
|
||||||
|
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||||
|
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||||
|
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||||||
|
.number {color: #6897bb}
|
||||||
|
.comment {color: #808080}
|
||||||
|
.whitespace {color: #505050}
|
||||||
|
.ST1 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||||||
|
.ST2 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||||
|
.ST0 {color: #287bde}
|
||||||
|
.literal {color: #cc7832}
|
||||||
|
-->
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Assignments/lab11_CalebFontenot/src/lab11_calebfontenot/DoWhile1.java</td></tr></table>
|
||||||
|
<pre>
|
||||||
|
<span class="comment">/*</span>
|
||||||
|
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt</span><span class="comment"> to change this license</span>
|
||||||
|
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java</span><span class="comment"> to edit this template</span>
|
||||||
|
<span class="comment"> */</span>
|
||||||
|
<span class="literal">package</span> lab11_calebfontenot;
|
||||||
|
|
||||||
|
<span class="comment">/**</span>
|
||||||
|
<span class="comment"> *</span>
|
||||||
|
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">caleb</span>
|
||||||
|
<span class="comment">*/</span>
|
||||||
|
<span class="literal">public</span> <span class="literal">class</span> DoWhile1 {
|
||||||
|
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">main</span>(String[] args) {
|
||||||
|
<span class="literal">int</span> i = <span class="number">0</span>;
|
||||||
|
<span class="literal">do</span> {
|
||||||
|
System.<span class="ST2">out</span>.println(i);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
<span class="literal">while</span> (i < <span class="number">10</span>);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
</pre></body>
|
||||||
|
</html>
|
54
Assignments/lab11_CalebFontenot/DoWhile2.html
Normal file
54
Assignments/lab11_CalebFontenot/DoWhile2.html
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>DoWhile2.java</title>
|
||||||
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||||
|
<style type="text/css">
|
||||||
|
<!--
|
||||||
|
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||||
|
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||||
|
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||||||
|
.number {color: #6897bb}
|
||||||
|
.string {color: #6a8759}
|
||||||
|
.comment {color: #808080}
|
||||||
|
.whitespace {color: #505050}
|
||||||
|
.ST1 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||||||
|
.ST2 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||||
|
.ST0 {color: #287bde}
|
||||||
|
.literal {color: #cc7832}
|
||||||
|
-->
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Assignments/lab11_CalebFontenot/src/lab11_calebfontenot/DoWhile2.java</td></tr></table>
|
||||||
|
<pre>
|
||||||
|
<span class="comment">/*</span>
|
||||||
|
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt</span><span class="comment"> to change this license</span>
|
||||||
|
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java</span><span class="comment"> to edit this template</span>
|
||||||
|
<span class="comment"> */</span>
|
||||||
|
<span class="literal">package</span> lab11_calebfontenot;
|
||||||
|
|
||||||
|
<span class="comment">/**</span>
|
||||||
|
<span class="comment"> *</span>
|
||||||
|
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">caleb</span>
|
||||||
|
<span class="comment">*/</span>
|
||||||
|
<span class="literal">public</span> <span class="literal">class</span> DoWhile2 {
|
||||||
|
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">main</span>(String[] args) {
|
||||||
|
<span class="literal">int</span> i = <span class="number">1</span>;
|
||||||
|
<span class="literal">do</span> {
|
||||||
|
|
||||||
|
System.<span class="ST2">out</span>.print(i + <span class="string">"</span><span class="string">, </span><span class="string">"</span>);
|
||||||
|
|
||||||
|
<span class="comment">// if number is divisable by 10, delete the last two characters and print a new line.</span>
|
||||||
|
<span class="literal">if</span> (i % <span class="number">10</span> == <span class="number">0</span>) {
|
||||||
|
System.<span class="ST2">out</span>.print(<span class="string">"</span><span class="literal">\b</span><span class="literal">\b</span><span class="literal">\n</span><span class="string">"</span>);
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
|
||||||
|
}
|
||||||
|
<span class="literal">while</span> (i <= <span class="number">100</span>);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
</pre></body>
|
||||||
|
</html>
|
52
Assignments/lab11_CalebFontenot/DoWhileEvent1.html
Normal file
52
Assignments/lab11_CalebFontenot/DoWhileEvent1.html
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>DoWhileEvent1.java</title>
|
||||||
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||||
|
<style type="text/css">
|
||||||
|
<!--
|
||||||
|
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||||
|
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||||
|
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||||||
|
.number {color: #6897bb}
|
||||||
|
.string {color: #6a8759}
|
||||||
|
.comment {color: #808080}
|
||||||
|
.whitespace {color: #505050}
|
||||||
|
.ST1 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||||||
|
.ST2 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||||
|
.ST0 {color: #287bde}
|
||||||
|
.literal {color: #cc7832}
|
||||||
|
-->
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Assignments/lab11_CalebFontenot/src/lab11_calebfontenot/DoWhileEvent1.java</td></tr></table>
|
||||||
|
<pre>
|
||||||
|
<span class="comment">/*</span>
|
||||||
|
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt</span><span class="comment"> to change this license</span>
|
||||||
|
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java</span><span class="comment"> to edit this template</span>
|
||||||
|
<span class="comment"> */</span>
|
||||||
|
<span class="literal">package</span> lab11_calebfontenot;
|
||||||
|
|
||||||
|
<span class="literal">import</span> java.util.Scanner;
|
||||||
|
|
||||||
|
<span class="comment">/**</span>
|
||||||
|
<span class="comment"> *</span>
|
||||||
|
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">caleb</span>
|
||||||
|
<span class="comment">*/</span>
|
||||||
|
<span class="literal">public</span> <span class="literal">class</span> DoWhileEvent1 {
|
||||||
|
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">main</span>(String[] args) {
|
||||||
|
Scanner scan = <span class="literal">new</span> Scanner(System.<span class="ST2">in</span>);
|
||||||
|
<span class="literal">int</span> num = <span class="number">0</span>;
|
||||||
|
<span class="literal">int</span> sum = <span class="number">0</span>;
|
||||||
|
<span class="literal">do</span> {
|
||||||
|
System.<span class="ST2">out</span>.print(<span class="string">"</span><span class="string">Please enter a positive number to add it to the sum or -1 to quit: </span><span class="string">"</span>);
|
||||||
|
num = scan.nextInt();
|
||||||
|
sum = num != -<span class="number">1</span> ? sum + num : sum;
|
||||||
|
} <span class="literal">while</span> (num != -<span class="number">1</span>);
|
||||||
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Total : </span><span class="string">"</span> + sum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
</pre></body>
|
||||||
|
</html>
|
55
Assignments/lab11_CalebFontenot/DoWhileEvent2.html
Normal file
55
Assignments/lab11_CalebFontenot/DoWhileEvent2.html
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>DoWhileEvent2.java</title>
|
||||||
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||||
|
<style type="text/css">
|
||||||
|
<!--
|
||||||
|
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||||
|
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||||
|
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||||||
|
.string {color: #6a8759}
|
||||||
|
.number {color: #6897bb}
|
||||||
|
.comment {color: #808080}
|
||||||
|
.whitespace {color: #505050}
|
||||||
|
.ST1 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||||||
|
.ST2 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||||
|
.ST0 {color: #287bde}
|
||||||
|
.literal {color: #cc7832}
|
||||||
|
-->
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Assignments/lab11_CalebFontenot/src/lab11_calebfontenot/DoWhileEvent2.java</td></tr></table>
|
||||||
|
<pre>
|
||||||
|
<span class="comment">/*</span>
|
||||||
|
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt</span><span class="comment"> to change this license</span>
|
||||||
|
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java</span><span class="comment"> to edit this template</span>
|
||||||
|
<span class="comment"> */</span>
|
||||||
|
<span class="literal">package</span> lab11_calebfontenot;
|
||||||
|
|
||||||
|
<span class="literal">import</span> java.util.Scanner;
|
||||||
|
|
||||||
|
<span class="comment">/**</span>
|
||||||
|
<span class="comment"> *</span>
|
||||||
|
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">caleb</span>
|
||||||
|
<span class="comment">*/</span>
|
||||||
|
<span class="literal">public</span> <span class="literal">class</span> DoWhileEvent2 {
|
||||||
|
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">main</span>(String[] args) {
|
||||||
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Please enter a positive number to add it to sum or -1 to quit</span><span class="string">"</span>);
|
||||||
|
Scanner scan = <span class="literal">new</span> Scanner(System.<span class="ST2">in</span>);
|
||||||
|
<span class="literal">int</span> num = scan.nextInt(); <span class="comment">//2 Condition: initialize the condition of the loop</span>
|
||||||
|
<span class="literal">int</span> sum = <span class="number">0</span>; <span class="comment">//1 task: Initialize the task</span>
|
||||||
|
<span class="literal">do</span> <span class="comment">//1 condition: What is the condition?</span>
|
||||||
|
{
|
||||||
|
sum += num; <span class="comment">//2 task: task of the loop and its update</span>
|
||||||
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Please enter a positive number to add it to sum or -1 to quit</span><span class="string">"</span>);
|
||||||
|
num = scan.nextInt();<span class="comment">//3 condition update the condition of the loop.</span>
|
||||||
|
}
|
||||||
|
<span class="literal">while</span> (num != -<span class="number">1</span>);
|
||||||
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Total </span><span class="string">"</span> + sum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
</pre></body>
|
||||||
|
</html>
|
70
Assignments/lab11_CalebFontenot/DoWhileEvent3.html
Normal file
70
Assignments/lab11_CalebFontenot/DoWhileEvent3.html
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>DoWhileEvent3.java</title>
|
||||||
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||||
|
<style type="text/css">
|
||||||
|
<!--
|
||||||
|
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||||
|
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||||
|
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||||||
|
.number {color: #6897bb}
|
||||||
|
.string {color: #6a8759}
|
||||||
|
.comment {color: #808080}
|
||||||
|
.whitespace {color: #505050}
|
||||||
|
.ST1 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||||||
|
.ST2 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||||
|
.ST0 {color: #287bde}
|
||||||
|
.literal {color: #cc7832}
|
||||||
|
.ST3 {font-family: monospace; font-weight: bold; font-style: italic}
|
||||||
|
-->
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Assignments/lab11_CalebFontenot/src/lab11_calebfontenot/DoWhileEvent3.java</td></tr></table>
|
||||||
|
<pre>
|
||||||
|
<span class="comment">/*</span>
|
||||||
|
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt</span><span class="comment"> to change this license</span>
|
||||||
|
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java</span><span class="comment"> to edit this template</span>
|
||||||
|
<span class="comment"> */</span>
|
||||||
|
<span class="literal">package</span> lab11_calebfontenot;
|
||||||
|
|
||||||
|
<span class="literal">import</span> java.util.Scanner;
|
||||||
|
|
||||||
|
<span class="comment">/**</span>
|
||||||
|
<span class="comment"> *</span>
|
||||||
|
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">caleb</span>
|
||||||
|
<span class="comment">*/</span>
|
||||||
|
<span class="literal">public</span> <span class="literal">class</span> DoWhileEvent3 {
|
||||||
|
|
||||||
|
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">main</span>(String[] args) {
|
||||||
|
<span class="comment">// Define variables</span>
|
||||||
|
<span class="literal">int</span> sum = <span class="number">0</span>, numInt = <span class="number">0</span>;
|
||||||
|
String num = <span class="string">"</span><span class="string">This can be literally anything, it just needs to be initialized</span><span class="string">"</span>;
|
||||||
|
|
||||||
|
<span class="comment">// Create scanner</span>
|
||||||
|
Scanner input = <span class="literal">new</span> Scanner(System.<span class="ST2">in</span>);
|
||||||
|
|
||||||
|
<span class="literal">do</span> {
|
||||||
|
System.<span class="ST2">out</span>.print(<span class="string">"</span><span class="string">Enter an integer to add to the sum (type x to exit): </span><span class="string">"</span>);
|
||||||
|
num = input.nextLine(); <span class="comment">//Read input from console</span>
|
||||||
|
<span class="literal">try</span> {
|
||||||
|
numInt = Integer.<span class="ST3">parseInt</span>(num); <span class="comment">// Parse input as integer</span>
|
||||||
|
} <span class="literal">catch</span> (Exception NumberFormatException) { <span class="comment">// Catch invalid inputs</span>
|
||||||
|
<span class="literal">if</span> (num.toLowerCase().equals(<span class="string">"</span><span class="string">x</span><span class="string">"</span>)) {
|
||||||
|
<span class="literal">break</span>;
|
||||||
|
} <span class="literal">else</span>;
|
||||||
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Invalid input!</span><span class="string">"</span>);
|
||||||
|
}
|
||||||
|
sum += numInt; <span class="comment">// add integer to the sum</span>
|
||||||
|
|
||||||
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Current sum: </span><span class="string">"</span> + sum);
|
||||||
|
} <span class="literal">while</span> (!(num.toLowerCase().equals(<span class="string">"</span><span class="string">x</span><span class="string">"</span>)));
|
||||||
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Exited loop!</span><span class="string">"</span>);
|
||||||
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Final sum: </span><span class="string">"</span> + sum);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
</pre></body>
|
||||||
|
</html>
|
44
Assignments/lab11_CalebFontenot/For1.html
Normal file
44
Assignments/lab11_CalebFontenot/For1.html
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>For1.java</title>
|
||||||
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||||
|
<style type="text/css">
|
||||||
|
<!--
|
||||||
|
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||||
|
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||||
|
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||||||
|
.number {color: #6897bb}
|
||||||
|
.comment {color: #808080}
|
||||||
|
.whitespace {color: #505050}
|
||||||
|
.ST1 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||||||
|
.ST2 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||||
|
.ST0 {color: #287bde}
|
||||||
|
.literal {color: #cc7832}
|
||||||
|
-->
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Assignments/lab11_CalebFontenot/src/lab11_calebfontenot/For1.java</td></tr></table>
|
||||||
|
<pre>
|
||||||
|
<span class="comment">/*</span>
|
||||||
|
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt</span><span class="comment"> to change this license</span>
|
||||||
|
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java</span><span class="comment"> to edit this template</span>
|
||||||
|
<span class="comment"> */</span>
|
||||||
|
<span class="literal">package</span> lab11_calebfontenot;
|
||||||
|
|
||||||
|
<span class="comment">/**</span>
|
||||||
|
<span class="comment"> *</span>
|
||||||
|
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">caleb</span>
|
||||||
|
<span class="comment">*/</span>
|
||||||
|
<span class="literal">public</span> <span class="literal">class</span> For1 {
|
||||||
|
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">main</span>(String[] args) {
|
||||||
|
<span class="literal">for</span> (<span class="literal">int</span> i=<span class="number">0</span>; i < <span class="number">10</span>; ++i) {
|
||||||
|
System.<span class="ST2">out</span>.println(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
</pre></body>
|
||||||
|
</html>
|
46
Assignments/lab11_CalebFontenot/For2.html
Normal file
46
Assignments/lab11_CalebFontenot/For2.html
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>For2.java</title>
|
||||||
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||||
|
<style type="text/css">
|
||||||
|
<!--
|
||||||
|
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||||
|
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||||
|
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||||||
|
.number {color: #6897bb}
|
||||||
|
.string {color: #6a8759}
|
||||||
|
.comment {color: #808080}
|
||||||
|
.whitespace {color: #505050}
|
||||||
|
.ST1 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||||||
|
.ST2 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||||
|
.ST0 {color: #287bde}
|
||||||
|
.literal {color: #cc7832}
|
||||||
|
.ST3 {font-family: monospace; font-weight: bold; font-style: italic}
|
||||||
|
-->
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Assignments/lab11_CalebFontenot/src/lab11_calebfontenot/For2.java</td></tr></table>
|
||||||
|
<pre>
|
||||||
|
<span class="comment">/*</span>
|
||||||
|
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt</span><span class="comment"> to change this license</span>
|
||||||
|
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java</span><span class="comment"> to edit this template</span>
|
||||||
|
<span class="comment"> */</span>
|
||||||
|
<span class="literal">package</span> lab11_calebfontenot;
|
||||||
|
|
||||||
|
<span class="comment">/**</span>
|
||||||
|
<span class="comment"> *</span>
|
||||||
|
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">caleb</span>
|
||||||
|
<span class="comment">*/</span>
|
||||||
|
<span class="literal">public</span> <span class="literal">class</span> For2 {
|
||||||
|
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">main</span>(String[] args) {
|
||||||
|
<span class="literal">for</span> (<span class="literal">int</span> i=<span class="number">10</span>; i < <span class="number">20</span>; ++i) {
|
||||||
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Square Root of </span><span class="string">"</span> + i + <span class="string">"</span><span class="string">: </span><span class="string">"</span> + Math.<span class="ST3">sqrt</span>(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
</pre></body>
|
||||||
|
</html>
|
46
Assignments/lab11_CalebFontenot/While1.html
Normal file
46
Assignments/lab11_CalebFontenot/While1.html
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>While1.java</title>
|
||||||
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||||
|
<style type="text/css">
|
||||||
|
<!--
|
||||||
|
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||||
|
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||||
|
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||||||
|
.number {color: #6897bb}
|
||||||
|
.comment {color: #808080}
|
||||||
|
.whitespace {color: #505050}
|
||||||
|
.ST1 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||||||
|
.ST2 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||||
|
.ST0 {color: #287bde}
|
||||||
|
.literal {color: #cc7832}
|
||||||
|
-->
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Assignments/lab11_CalebFontenot/src/lab11_calebfontenot/While1.java</td></tr></table>
|
||||||
|
<pre>
|
||||||
|
<span class="comment">/*</span>
|
||||||
|
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt</span><span class="comment"> to change this license</span>
|
||||||
|
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java</span><span class="comment"> to edit this template</span>
|
||||||
|
<span class="comment"> */</span>
|
||||||
|
<span class="literal">package</span> lab11_calebfontenot;
|
||||||
|
|
||||||
|
<span class="comment">/**</span>
|
||||||
|
<span class="comment"> *</span>
|
||||||
|
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">caleb</span>
|
||||||
|
<span class="comment">*/</span>
|
||||||
|
<span class="literal">public</span> <span class="literal">class</span> While1 {
|
||||||
|
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">main</span>(String[] args) {
|
||||||
|
<span class="literal">int</span> i = <span class="number">0</span>;
|
||||||
|
<span class="literal">while</span> (i < <span class="number">10</span>)
|
||||||
|
{
|
||||||
|
System.<span class="ST2">out</span>.println(i);
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
</pre></body>
|
||||||
|
</html>
|
43
Assignments/lab11_CalebFontenot/While2.html
Normal file
43
Assignments/lab11_CalebFontenot/While2.html
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>While2.java</title>
|
||||||
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||||
|
<style type="text/css">
|
||||||
|
<!--
|
||||||
|
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||||
|
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||||
|
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||||||
|
.number {color: #6897bb}
|
||||||
|
.comment {color: #808080}
|
||||||
|
.whitespace {color: #505050}
|
||||||
|
.ST1 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||||||
|
.ST2 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||||
|
.ST0 {color: #287bde}
|
||||||
|
.literal {color: #cc7832}
|
||||||
|
-->
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Assignments/lab11_CalebFontenot/src/lab11_calebfontenot/While2.java</td></tr></table>
|
||||||
|
<pre>
|
||||||
|
<span class="comment">/*</span>
|
||||||
|
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt</span><span class="comment"> to change this license</span>
|
||||||
|
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java</span><span class="comment"> to edit this template</span>
|
||||||
|
<span class="comment"> */</span>
|
||||||
|
<span class="literal">package</span> lab11_calebfontenot;
|
||||||
|
|
||||||
|
<span class="comment">/**</span>
|
||||||
|
<span class="comment"> *</span>
|
||||||
|
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">caleb</span>
|
||||||
|
<span class="comment">*/</span>
|
||||||
|
<span class="literal">public</span> <span class="literal">class</span> While2 {
|
||||||
|
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">main</span>(String[] args) {
|
||||||
|
<span class="literal">int</span> i = <span class="number">0</span>;
|
||||||
|
<span class="literal">while</span> (i < <span class="number">10</span>)
|
||||||
|
System.<span class="ST2">out</span>.println(i++);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
</pre></body>
|
||||||
|
</html>
|
43
Assignments/lab11_CalebFontenot/While3.html
Normal file
43
Assignments/lab11_CalebFontenot/While3.html
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>While3.java</title>
|
||||||
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||||
|
<style type="text/css">
|
||||||
|
<!--
|
||||||
|
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||||
|
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||||
|
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||||||
|
.number {color: #6897bb}
|
||||||
|
.comment {color: #808080}
|
||||||
|
.whitespace {color: #505050}
|
||||||
|
.ST1 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||||||
|
.ST2 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||||
|
.ST0 {color: #287bde}
|
||||||
|
.literal {color: #cc7832}
|
||||||
|
-->
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Assignments/lab11_CalebFontenot/src/lab11_calebfontenot/While3.java</td></tr></table>
|
||||||
|
<pre>
|
||||||
|
<span class="comment">/*</span>
|
||||||
|
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt</span><span class="comment"> to change this license</span>
|
||||||
|
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java</span><span class="comment"> to edit this template</span>
|
||||||
|
<span class="comment"> */</span>
|
||||||
|
<span class="literal">package</span> lab11_calebfontenot;
|
||||||
|
|
||||||
|
<span class="comment">/**</span>
|
||||||
|
<span class="comment"> *</span>
|
||||||
|
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">caleb</span>
|
||||||
|
<span class="comment">*/</span>
|
||||||
|
<span class="literal">public</span> <span class="literal">class</span> While3 {
|
||||||
|
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">main</span>(String[] args) {
|
||||||
|
<span class="literal">int</span> i = <span class="number">10</span>;
|
||||||
|
<span class="literal">while</span> (i > -<span class="number">1</span>)
|
||||||
|
System.<span class="ST2">out</span>.println(i--);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
</pre></body>
|
||||||
|
</html>
|
55
Assignments/lab11_CalebFontenot/WhileEvent1.html
Normal file
55
Assignments/lab11_CalebFontenot/WhileEvent1.html
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>WhileEvent1.java</title>
|
||||||
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||||
|
<style type="text/css">
|
||||||
|
<!--
|
||||||
|
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||||
|
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||||
|
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||||||
|
.string {color: #6a8759}
|
||||||
|
.number {color: #6897bb}
|
||||||
|
.comment {color: #808080}
|
||||||
|
.whitespace {color: #505050}
|
||||||
|
.ST1 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||||||
|
.ST2 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||||
|
.ST0 {color: #287bde}
|
||||||
|
.literal {color: #cc7832}
|
||||||
|
-->
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Assignments/lab11_CalebFontenot/src/lab11_calebfontenot/WhileEvent1.java</td></tr></table>
|
||||||
|
<pre>
|
||||||
|
<span class="comment">/*</span>
|
||||||
|
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt</span><span class="comment"> to change this license</span>
|
||||||
|
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java</span><span class="comment"> to edit this template</span>
|
||||||
|
<span class="comment"> */</span>
|
||||||
|
<span class="literal">package</span> lab11_calebfontenot;
|
||||||
|
|
||||||
|
<span class="literal">import</span> java.util.Scanner;
|
||||||
|
|
||||||
|
<span class="comment">/**</span>
|
||||||
|
<span class="comment"> *</span>
|
||||||
|
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">caleb</span>
|
||||||
|
<span class="comment">*/</span>
|
||||||
|
<span class="literal">public</span> <span class="literal">class</span> WhileEvent1 {
|
||||||
|
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">main</span>(String[] args) {
|
||||||
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Please enter a positive number to add it to sum or -1 to quit</span><span class="string">"</span>);
|
||||||
|
Scanner scan = <span class="literal">new</span> Scanner(System.<span class="ST2">in</span>);
|
||||||
|
<span class="literal">int</span> num = scan.nextInt(); <span class="comment">//2 Condition: initialize the condition of the loop</span>
|
||||||
|
<span class="literal">int</span> sum = <span class="number">0</span>; <span class="comment">//1 task: Initialize the task</span>
|
||||||
|
<span class="literal">while</span> (num != -<span class="number">1</span>) <span class="comment">//1 condition: What is the condition?</span>
|
||||||
|
{
|
||||||
|
sum += num; <span class="comment">//2 task: task of the loop and its update</span>
|
||||||
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Please enter a positive number to add it to sum or -1 to quit</span><span class="string">"</span>);
|
||||||
|
num = scan.nextInt();<span class="comment">//3 condition update the condition of the loop.</span>
|
||||||
|
}
|
||||||
|
|
||||||
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Total </span><span class="string">"</span> + sum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
</pre></body>
|
||||||
|
</html>
|
70
Assignments/lab11_CalebFontenot/WhileEvent3.html
Normal file
70
Assignments/lab11_CalebFontenot/WhileEvent3.html
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>WhileEvent3.java</title>
|
||||||
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
|
||||||
|
<style type="text/css">
|
||||||
|
<!--
|
||||||
|
body {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||||
|
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace; font-weight: bold}
|
||||||
|
table {color: #888888; background-color: #313335; font-family: monospace; font-weight: bold}
|
||||||
|
.number {color: #6897bb}
|
||||||
|
.string {color: #6a8759}
|
||||||
|
.comment {color: #808080}
|
||||||
|
.whitespace {color: #505050}
|
||||||
|
.ST1 {color: #ffc66d; font-family: monospace; font-weight: bold; font-style: italic}
|
||||||
|
.ST2 {color: #9876aa; font-family: monospace; font-weight: bold; font-style: italic}
|
||||||
|
.ST0 {color: #287bde}
|
||||||
|
.literal {color: #cc7832}
|
||||||
|
.ST3 {font-family: monospace; font-weight: bold; font-style: italic}
|
||||||
|
-->
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Assignments/lab11_CalebFontenot/src/lab11_calebfontenot/WhileEvent3.java</td></tr></table>
|
||||||
|
<pre>
|
||||||
|
<span class="comment">/*</span>
|
||||||
|
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt</span><span class="comment"> to change this license</span>
|
||||||
|
<span class="comment"> * Click </span><span class="ST0">nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java</span><span class="comment"> to edit this template</span>
|
||||||
|
<span class="comment"> */</span>
|
||||||
|
<span class="literal">package</span> lab11_calebfontenot;
|
||||||
|
|
||||||
|
<span class="literal">import</span> java.util.Scanner;
|
||||||
|
|
||||||
|
<span class="comment">/**</span>
|
||||||
|
<span class="comment"> *</span>
|
||||||
|
<span class="comment"> * </span><span class="comment">@author</span> <span class="comment">caleb</span>
|
||||||
|
<span class="comment">*/</span>
|
||||||
|
<span class="literal">public</span> <span class="literal">class</span> WhileEvent3 {
|
||||||
|
|
||||||
|
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST1">main</span>(String[] args) {
|
||||||
|
<span class="comment">// Define variables</span>
|
||||||
|
<span class="literal">int</span> sum = <span class="number">0</span>, numInt = <span class="number">0</span>;
|
||||||
|
String num = <span class="string">"</span><span class="string">This can be literally anything, it just needs to be initialized</span><span class="string">"</span>;
|
||||||
|
|
||||||
|
<span class="comment">// Create scanner</span>
|
||||||
|
Scanner input = <span class="literal">new</span> Scanner(System.<span class="ST2">in</span>);
|
||||||
|
|
||||||
|
<span class="literal">while</span> (!(num.toLowerCase().equals(<span class="string">"</span><span class="string">x</span><span class="string">"</span>))) {
|
||||||
|
System.<span class="ST2">out</span>.print(<span class="string">"</span><span class="string">Enter an integer to add to the sum (type x to exit): </span><span class="string">"</span>);
|
||||||
|
num = input.nextLine(); <span class="comment">//Read input from console</span>
|
||||||
|
<span class="literal">try</span> {
|
||||||
|
numInt = Integer.<span class="ST3">parseInt</span>(num); <span class="comment">// Parse input as integer</span>
|
||||||
|
} <span class="literal">catch</span> (Exception NumberFormatException) { <span class="comment">// Catch invalid inputs</span>
|
||||||
|
<span class="literal">if</span> (num.toLowerCase().equals(<span class="string">"</span><span class="string">x</span><span class="string">"</span>)) {
|
||||||
|
<span class="literal">break</span>;
|
||||||
|
} <span class="literal">else</span>;
|
||||||
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Invalid input!</span><span class="string">"</span>);
|
||||||
|
}
|
||||||
|
sum += numInt; <span class="comment">// add integer to the sum</span>
|
||||||
|
|
||||||
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Current sum: </span><span class="string">"</span> + sum);
|
||||||
|
}
|
||||||
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Exited loop!</span><span class="string">"</span>);
|
||||||
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Final sum: </span><span class="string">"</span> + sum);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
</pre></body>
|
||||||
|
</html>
|
73
Assignments/lab11_CalebFontenot/build.xml
Normal file
73
Assignments/lab11_CalebFontenot/build.xml
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!-- You may freely edit this file. See commented blocks below for -->
|
||||||
|
<!-- some examples of how to customize the build. -->
|
||||||
|
<!-- (If you delete it and reopen the project it will be recreated.) -->
|
||||||
|
<!-- By default, only the Clean and Build commands use this build script. -->
|
||||||
|
<!-- Commands such as Run, Debug, and Test only use this build script if -->
|
||||||
|
<!-- the Compile on Save feature is turned off for the project. -->
|
||||||
|
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
|
||||||
|
<!-- in the project's Project Properties dialog box.-->
|
||||||
|
<project name="lab11_CalebFontenot" default="default" basedir=".">
|
||||||
|
<description>Builds, tests, and runs the project lab11_CalebFontenot.</description>
|
||||||
|
<import file="nbproject/build-impl.xml"/>
|
||||||
|
<!--
|
||||||
|
|
||||||
|
There exist several targets which are by default empty and which can be
|
||||||
|
used for execution of your tasks. These targets are usually executed
|
||||||
|
before and after some main targets. They are:
|
||||||
|
|
||||||
|
-pre-init: called before initialization of project properties
|
||||||
|
-post-init: called after initialization of project properties
|
||||||
|
-pre-compile: called before javac compilation
|
||||||
|
-post-compile: called after javac compilation
|
||||||
|
-pre-compile-single: called before javac compilation of single file
|
||||||
|
-post-compile-single: called after javac compilation of single file
|
||||||
|
-pre-compile-test: called before javac compilation of JUnit tests
|
||||||
|
-post-compile-test: called after javac compilation of JUnit tests
|
||||||
|
-pre-compile-test-single: called before javac compilation of single JUnit test
|
||||||
|
-post-compile-test-single: called after javac compilation of single JUunit test
|
||||||
|
-pre-jar: called before JAR building
|
||||||
|
-post-jar: called after JAR building
|
||||||
|
-post-clean: called after cleaning build products
|
||||||
|
|
||||||
|
(Targets beginning with '-' are not intended to be called on their own.)
|
||||||
|
|
||||||
|
Example of inserting an obfuscator after compilation could look like this:
|
||||||
|
|
||||||
|
<target name="-post-compile">
|
||||||
|
<obfuscate>
|
||||||
|
<fileset dir="${build.classes.dir}"/>
|
||||||
|
</obfuscate>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
For list of available properties check the imported
|
||||||
|
nbproject/build-impl.xml file.
|
||||||
|
|
||||||
|
|
||||||
|
Another way to customize the build is by overriding existing main targets.
|
||||||
|
The targets of interest are:
|
||||||
|
|
||||||
|
-init-macrodef-javac: defines macro for javac compilation
|
||||||
|
-init-macrodef-junit: defines macro for junit execution
|
||||||
|
-init-macrodef-debug: defines macro for class debugging
|
||||||
|
-init-macrodef-java: defines macro for class execution
|
||||||
|
-do-jar: JAR building
|
||||||
|
run: execution of project
|
||||||
|
-javadoc-build: Javadoc generation
|
||||||
|
test-report: JUnit report generation
|
||||||
|
|
||||||
|
An example of overriding the target for project execution could look like this:
|
||||||
|
|
||||||
|
<target name="run" depends="lab11_CalebFontenot-impl.jar">
|
||||||
|
<exec dir="bin" executable="launcher.exe">
|
||||||
|
<arg file="${dist.jar}"/>
|
||||||
|
</exec>
|
||||||
|
</target>
|
||||||
|
|
||||||
|
Notice that the overridden target depends on the jar target and not only on
|
||||||
|
the compile target as the regular run target does. Again, for a list of available
|
||||||
|
properties which you can use, check the target you are overriding in the
|
||||||
|
nbproject/build-impl.xml file.
|
||||||
|
|
||||||
|
-->
|
||||||
|
</project>
|
3
Assignments/lab11_CalebFontenot/manifest.mf
Normal file
3
Assignments/lab11_CalebFontenot/manifest.mf
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
Manifest-Version: 1.0
|
||||||
|
X-COMMENT: Main-Class will be added automatically by build
|
||||||
|
|
1771
Assignments/lab11_CalebFontenot/nbproject/build-impl.xml
Normal file
1771
Assignments/lab11_CalebFontenot/nbproject/build-impl.xml
Normal file
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,8 @@
|
|||||||
|
build.xml.data.CRC32=9e8c47b8
|
||||||
|
build.xml.script.CRC32=9b03d5fc
|
||||||
|
build.xml.stylesheet.CRC32=f85dc8f2@1.104.0.48
|
||||||
|
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
|
||||||
|
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
|
||||||
|
nbproject/build-impl.xml.data.CRC32=9e8c47b8
|
||||||
|
nbproject/build-impl.xml.script.CRC32=81e4946a
|
||||||
|
nbproject/build-impl.xml.stylesheet.CRC32=12e0a6c2@1.104.0.48
|
95
Assignments/lab11_CalebFontenot/nbproject/project.properties
Normal file
95
Assignments/lab11_CalebFontenot/nbproject/project.properties
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
annotation.processing.enabled=true
|
||||||
|
annotation.processing.enabled.in.editor=false
|
||||||
|
annotation.processing.processor.options=
|
||||||
|
annotation.processing.processors.list=
|
||||||
|
annotation.processing.run.all.processors=true
|
||||||
|
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
|
||||||
|
build.classes.dir=${build.dir}/classes
|
||||||
|
build.classes.excludes=**/*.java,**/*.form
|
||||||
|
# This directory is removed when the project is cleaned:
|
||||||
|
build.dir=build
|
||||||
|
build.generated.dir=${build.dir}/generated
|
||||||
|
build.generated.sources.dir=${build.dir}/generated-sources
|
||||||
|
# Only compile against the classpath explicitly listed here:
|
||||||
|
build.sysclasspath=ignore
|
||||||
|
build.test.classes.dir=${build.dir}/test/classes
|
||||||
|
build.test.results.dir=${build.dir}/test/results
|
||||||
|
# Uncomment to specify the preferred debugger connection transport:
|
||||||
|
#debug.transport=dt_socket
|
||||||
|
debug.classpath=\
|
||||||
|
${run.classpath}
|
||||||
|
debug.modulepath=\
|
||||||
|
${run.modulepath}
|
||||||
|
debug.test.classpath=\
|
||||||
|
${run.test.classpath}
|
||||||
|
debug.test.modulepath=\
|
||||||
|
${run.test.modulepath}
|
||||||
|
# Files in build.classes.dir which should be excluded from distribution jar
|
||||||
|
dist.archive.excludes=
|
||||||
|
# This directory is removed when the project is cleaned:
|
||||||
|
dist.dir=dist
|
||||||
|
dist.jar=${dist.dir}/lab11_CalebFontenot.jar
|
||||||
|
dist.javadoc.dir=${dist.dir}/javadoc
|
||||||
|
dist.jlink.dir=${dist.dir}/jlink
|
||||||
|
dist.jlink.output=${dist.jlink.dir}/lab11_CalebFontenot
|
||||||
|
excludes=
|
||||||
|
includes=**
|
||||||
|
jar.compress=false
|
||||||
|
javac.classpath=
|
||||||
|
# Space-separated list of extra javac options
|
||||||
|
javac.compilerargs=
|
||||||
|
javac.deprecation=false
|
||||||
|
javac.external.vm=true
|
||||||
|
javac.modulepath=
|
||||||
|
javac.processormodulepath=
|
||||||
|
javac.processorpath=\
|
||||||
|
${javac.classpath}
|
||||||
|
javac.source=19
|
||||||
|
javac.target=19
|
||||||
|
javac.test.classpath=\
|
||||||
|
${javac.classpath}:\
|
||||||
|
${build.classes.dir}
|
||||||
|
javac.test.modulepath=\
|
||||||
|
${javac.modulepath}
|
||||||
|
javac.test.processorpath=\
|
||||||
|
${javac.test.classpath}
|
||||||
|
javadoc.additionalparam=
|
||||||
|
javadoc.author=false
|
||||||
|
javadoc.encoding=${source.encoding}
|
||||||
|
javadoc.html5=false
|
||||||
|
javadoc.noindex=false
|
||||||
|
javadoc.nonavbar=false
|
||||||
|
javadoc.notree=false
|
||||||
|
javadoc.private=false
|
||||||
|
javadoc.splitindex=true
|
||||||
|
javadoc.use=true
|
||||||
|
javadoc.version=false
|
||||||
|
javadoc.windowtitle=
|
||||||
|
# The jlink additional root modules to resolve
|
||||||
|
jlink.additionalmodules=
|
||||||
|
# The jlink additional command line parameters
|
||||||
|
jlink.additionalparam=
|
||||||
|
jlink.launcher=true
|
||||||
|
jlink.launcher.name=lab11_CalebFontenot
|
||||||
|
main.class=lab11_calebfontenot.Lab11_CalebFontenot
|
||||||
|
manifest.file=manifest.mf
|
||||||
|
meta.inf.dir=${src.dir}/META-INF
|
||||||
|
mkdist.disabled=false
|
||||||
|
platform.active=default_platform
|
||||||
|
run.classpath=\
|
||||||
|
${javac.classpath}:\
|
||||||
|
${build.classes.dir}
|
||||||
|
# Space-separated list of JVM arguments used when running the project.
|
||||||
|
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
|
||||||
|
# To set system properties for unit tests define test-sys-prop.name=value:
|
||||||
|
run.jvmargs=
|
||||||
|
run.modulepath=\
|
||||||
|
${javac.modulepath}
|
||||||
|
run.test.classpath=\
|
||||||
|
${javac.test.classpath}:\
|
||||||
|
${build.test.classes.dir}
|
||||||
|
run.test.modulepath=\
|
||||||
|
${javac.test.modulepath}
|
||||||
|
source.encoding=UTF-8
|
||||||
|
src.dir=src
|
||||||
|
test.src.dir=test
|
15
Assignments/lab11_CalebFontenot/nbproject/project.xml
Normal file
15
Assignments/lab11_CalebFontenot/nbproject/project.xml
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://www.netbeans.org/ns/project/1">
|
||||||
|
<type>org.netbeans.modules.java.j2seproject</type>
|
||||||
|
<configuration>
|
||||||
|
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
|
||||||
|
<name>lab11_CalebFontenot</name>
|
||||||
|
<source-roots>
|
||||||
|
<root id="src.dir"/>
|
||||||
|
</source-roots>
|
||||||
|
<test-roots>
|
||||||
|
<root id="test.src.dir"/>
|
||||||
|
</test-roots>
|
||||||
|
</data>
|
||||||
|
</configuration>
|
||||||
|
</project>
|
@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||||
|
*/
|
||||||
|
package lab11_calebfontenot;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author caleb
|
||||||
|
*/
|
||||||
|
public class DoWhile1 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int i = 0;
|
||||||
|
do {
|
||||||
|
System.out.println(i);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
while (i < 10);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||||
|
*/
|
||||||
|
package lab11_calebfontenot;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author caleb
|
||||||
|
*/
|
||||||
|
public class DoWhile2 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int i = 1;
|
||||||
|
do {
|
||||||
|
|
||||||
|
System.out.print(i + ", ");
|
||||||
|
|
||||||
|
// if number is divisable by 10, delete the last two characters and print a new line.
|
||||||
|
if (i % 10 == 0) {
|
||||||
|
System.out.print("\b\b\n");
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
|
||||||
|
}
|
||||||
|
while (i <= 100);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||||
|
*/
|
||||||
|
package lab11_calebfontenot;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author caleb
|
||||||
|
*/
|
||||||
|
public class DoWhileEvent1 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Scanner scan = new Scanner(System.in);
|
||||||
|
int num = 0;
|
||||||
|
int sum = 0;
|
||||||
|
do {
|
||||||
|
System.out.print("Please enter a positive number to add it to the sum or -1 to quit: ");
|
||||||
|
num = scan.nextInt();
|
||||||
|
sum = num != -1 ? sum + num : sum;
|
||||||
|
} while (num != -1);
|
||||||
|
System.out.println("Total : " + sum);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||||
|
*/
|
||||||
|
package lab11_calebfontenot;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author caleb
|
||||||
|
*/
|
||||||
|
public class DoWhileEvent2 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println("Please enter a positive number to add it to sum or -1 to quit");
|
||||||
|
Scanner scan = new Scanner(System.in);
|
||||||
|
int num = scan.nextInt(); //2 Condition: initialize the condition of the loop
|
||||||
|
int sum = 0; //1 task: Initialize the task
|
||||||
|
do //1 condition: What is the condition?
|
||||||
|
{
|
||||||
|
sum += num; //2 task: task of the loop and its update
|
||||||
|
System.out.println("Please enter a positive number to add it to sum or -1 to quit");
|
||||||
|
num = scan.nextInt();//3 condition update the condition of the loop.
|
||||||
|
}
|
||||||
|
while (num != -1);
|
||||||
|
System.out.println("Total " + sum);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||||
|
*/
|
||||||
|
package lab11_calebfontenot;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author caleb
|
||||||
|
*/
|
||||||
|
public class DoWhileEvent3 {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// Define variables
|
||||||
|
int sum = 0, numInt = 0;
|
||||||
|
String num = "This can be literally anything, it just needs to be initialized";
|
||||||
|
|
||||||
|
// Create scanner
|
||||||
|
Scanner input = new Scanner(System.in);
|
||||||
|
|
||||||
|
do {
|
||||||
|
System.out.print("Enter an integer to add to the sum (type x to exit): ");
|
||||||
|
num = input.nextLine(); //Read input from console
|
||||||
|
try {
|
||||||
|
numInt = Integer.parseInt(num); // Parse input as integer
|
||||||
|
} catch (Exception NumberFormatException) { // Catch invalid inputs
|
||||||
|
if (num.toLowerCase().equals("x")) {
|
||||||
|
break;
|
||||||
|
} else;
|
||||||
|
System.out.println("Invalid input!");
|
||||||
|
}
|
||||||
|
sum += numInt; // add integer to the sum
|
||||||
|
|
||||||
|
System.out.println("Current sum: " + sum);
|
||||||
|
} while (!(num.toLowerCase().equals("x")));
|
||||||
|
System.out.println("Exited loop!");
|
||||||
|
System.out.println("Final sum: " + sum);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||||
|
*/
|
||||||
|
package lab11_calebfontenot;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author caleb
|
||||||
|
*/
|
||||||
|
public class For1 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
for (int i=0; i < 10; ++i) {
|
||||||
|
System.out.println(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
/*
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||||
|
*/
|
||||||
|
package lab11_calebfontenot;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author caleb
|
||||||
|
*/
|
||||||
|
public class For2 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
for (int i=10; i < 20; ++i) {
|
||||||
|
System.out.println("Square Root of " + i + ": " + Math.sqrt(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template
|
||||||
|
*/
|
||||||
|
//package lab11_calebfontenot;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author caleb
|
||||||
|
*/
|
||||||
|
public class Lab11_CalebFontenot {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param args the command line arguments
|
||||||
|
*/
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println("\uDD14");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||||
|
*/
|
||||||
|
package lab11_calebfontenot;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author caleb
|
||||||
|
*/
|
||||||
|
public class While1 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int i = 0;
|
||||||
|
while (i < 10)
|
||||||
|
{
|
||||||
|
System.out.println(i);
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||||
|
*/
|
||||||
|
package lab11_calebfontenot;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author caleb
|
||||||
|
*/
|
||||||
|
public class While2 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int i = 0;
|
||||||
|
while (i < 10)
|
||||||
|
System.out.println(i++);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||||
|
*/
|
||||||
|
package lab11_calebfontenot;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author caleb
|
||||||
|
*/
|
||||||
|
public class While3 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
int i = 10;
|
||||||
|
while (i > -1)
|
||||||
|
System.out.println(i--);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||||
|
*/
|
||||||
|
package lab11_calebfontenot;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author caleb
|
||||||
|
*/
|
||||||
|
public class WhileEvent1 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println("Please enter a positive number to add it to sum or -1 to quit");
|
||||||
|
Scanner scan = new Scanner(System.in);
|
||||||
|
int num = scan.nextInt(); //2 Condition: initialize the condition of the loop
|
||||||
|
int sum = 0; //1 task: Initialize the task
|
||||||
|
while (num != -1) //1 condition: What is the condition?
|
||||||
|
{
|
||||||
|
sum += num; //2 task: task of the loop and its update
|
||||||
|
System.out.println("Please enter a positive number to add it to sum or -1 to quit");
|
||||||
|
num = scan.nextInt();//3 condition update the condition of the loop.
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Total " + sum);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||||
|
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||||
|
*/
|
||||||
|
package lab11_calebfontenot;
|
||||||
|
|
||||||
|
import java.util.Scanner;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author caleb
|
||||||
|
*/
|
||||||
|
public class WhileEvent3 {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
// Define variables
|
||||||
|
int sum = 0, numInt = 0;
|
||||||
|
String num = "This can be literally anything, it just needs to be initialized";
|
||||||
|
|
||||||
|
// Create scanner
|
||||||
|
Scanner input = new Scanner(System.in);
|
||||||
|
|
||||||
|
while (!(num.toLowerCase().equals("x"))) {
|
||||||
|
System.out.print("Enter an integer to add to the sum (type x to exit): ");
|
||||||
|
num = input.nextLine(); //Read input from console
|
||||||
|
try {
|
||||||
|
numInt = Integer.parseInt(num); // Parse input as integer
|
||||||
|
} catch (Exception NumberFormatException) { // Catch invalid inputs
|
||||||
|
if (num.toLowerCase().equals("x")) {
|
||||||
|
break;
|
||||||
|
} else;
|
||||||
|
System.out.println("Invalid input!");
|
||||||
|
}
|
||||||
|
sum += numInt; // add integer to the sum
|
||||||
|
|
||||||
|
System.out.println("Current sum: " + sum);
|
||||||
|
}
|
||||||
|
System.out.println("Exited loop!");
|
||||||
|
System.out.println("Final sum: " + sum);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
BIN
ZIPs/lab11_CalebFontenot.zip
Normal file
BIN
ZIPs/lab11_CalebFontenot.zip
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user