Finish Lab10
This commit is contained in:
parent
f4bc7fdca4
commit
bf56587261
@ -53,16 +53,36 @@ table {color: #888888; background-color: #313335; font-family: monospace; font-w
|
|||||||
userResponse = input.next();
|
userResponse = input.next();
|
||||||
|
|
||||||
<span class="literal">if</span> (userResponse.toLowerCase().charAt(<span class="number">0</span>) == <span class="string">'</span><span class="string">y</span><span class="string">'</span>) {
|
<span class="literal">if</span> (userResponse.toLowerCase().charAt(<span class="number">0</span>) == <span class="string">'</span><span class="string">y</span><span class="string">'</span>) {
|
||||||
<span class="comment">// User has responded with 'y'</span>
|
<span class="literal">if</span> (userResponse.length() > <span class="number">1</span>) { <span class="comment">// User has entered a string that starts with y</span>
|
||||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">You typed '</span><span class="string">"</span> + userResponse + <span class="string">'</span><span class="string">\'</span><span class="string">'</span>);
|
<span class="comment">// Check if string == yes</span>
|
||||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">ok!</span><span class="string">"</span>);
|
<span class="literal">if</span> (userResponse.toLowerCase().equals(<span class="string">"</span><span class="string">yes</span><span class="string">"</span>)) {
|
||||||
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">You typed '</span><span class="string">"</span> + userResponse + <span class="string">'</span><span class="string">\'</span><span class="string">'</span>);
|
||||||
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">ok!</span><span class="string">"</span>);
|
||||||
|
} <span class="literal">else</span> {
|
||||||
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Invalid input! You entered '</span><span class="string">"</span> + userResponse + <span class="string">'</span><span class="string">\'</span><span class="string">'</span>);
|
||||||
|
}
|
||||||
|
} <span class="literal">else</span> {
|
||||||
|
<span class="comment">// User has responded with 'y'</span>
|
||||||
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">You typed '</span><span class="string">"</span> + userResponse + <span class="string">'</span><span class="string">\'</span><span class="string">'</span>);
|
||||||
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">ok!</span><span class="string">"</span>);
|
||||||
|
}
|
||||||
} <span class="literal">else</span> <span class="literal">if</span> (userResponse.toLowerCase().charAt(<span class="number">0</span>) == <span class="string">'</span><span class="string">n</span><span class="string">'</span>) {
|
} <span class="literal">else</span> <span class="literal">if</span> (userResponse.toLowerCase().charAt(<span class="number">0</span>) == <span class="string">'</span><span class="string">n</span><span class="string">'</span>) {
|
||||||
<span class="comment">// User has responded with 'n'</span>
|
<span class="literal">if</span> (userResponse.length() > <span class="number">1</span>) { <span class="comment">// User has entered a string that starts with y</span>
|
||||||
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">You typed </span><span class="string">"</span> + userResponse.charAt(<span class="number">0</span>));
|
<span class="comment">// Check if string == yes</span>
|
||||||
<span class="comment">// Kill the loop.</span>
|
<span class="literal">if</span> (userResponse.toLowerCase().equals(<span class="string">"</span><span class="string">no</span><span class="string">"</span>)) {
|
||||||
loopToggle = <span class="literal">false</span>;
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">You typed '</span><span class="string">"</span> + userResponse + <span class="string">'</span><span class="string">\'</span><span class="string">'</span>);
|
||||||
} <span class="comment">// Invalid input handling</span>
|
<span class="comment">// Kill the loop.</span>
|
||||||
<span class="literal">else</span> {
|
loopToggle = <span class="literal">false</span>;
|
||||||
|
} <span class="literal">else</span> {
|
||||||
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">Invalid input! You entered '</span><span class="string">"</span> + userResponse + <span class="string">'</span><span class="string">\'</span><span class="string">'</span>);
|
||||||
|
}
|
||||||
|
} <span class="literal">else</span> {
|
||||||
|
<span class="comment">// User has responded with 'n'</span>
|
||||||
|
System.<span class="ST2">out</span>.println(<span class="string">"</span><span class="string">You typed </span><span class="string">"</span> + userResponse.charAt(<span class="number">0</span>));
|
||||||
|
<span class="comment">// Kill the loop.</span>
|
||||||
|
loopToggle = <span class="literal">false</span>;
|
||||||
|
}
|
||||||
|
} <span class="literal">else</span> { <span class="comment">// Invalid input handling</span>
|
||||||
<span class="comment">// Attempt to parse string as an integer.</span>
|
<span class="comment">// Attempt to parse string as an integer.</span>
|
||||||
<span class="literal">try</span> {
|
<span class="literal">try</span> {
|
||||||
parseCheck = Integer.<span class="ST3">parseInt</span>(userResponse);
|
parseCheck = Integer.<span class="ST3">parseInt</span>(userResponse);
|
||||||
|
@ -28,16 +28,36 @@ public class CharacterClassStringClass {
|
|||||||
userResponse = input.next();
|
userResponse = input.next();
|
||||||
|
|
||||||
if (userResponse.toLowerCase().charAt(0) == 'y') {
|
if (userResponse.toLowerCase().charAt(0) == 'y') {
|
||||||
// User has responded with 'y'
|
if (userResponse.length() > 1) { // User has entered a string that starts with y
|
||||||
System.out.println("You typed '" + userResponse + '\'');
|
// Check if string == yes
|
||||||
System.out.println("ok!");
|
if (userResponse.toLowerCase().equals("yes")) {
|
||||||
|
System.out.println("You typed '" + userResponse + '\'');
|
||||||
|
System.out.println("ok!");
|
||||||
|
} else {
|
||||||
|
System.out.println("Invalid input! You entered '" + userResponse + '\'');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// User has responded with 'y'
|
||||||
|
System.out.println("You typed '" + userResponse + '\'');
|
||||||
|
System.out.println("ok!");
|
||||||
|
}
|
||||||
} else if (userResponse.toLowerCase().charAt(0) == 'n') {
|
} else if (userResponse.toLowerCase().charAt(0) == 'n') {
|
||||||
// User has responded with 'n'
|
if (userResponse.length() > 1) { // User has entered a string that starts with y
|
||||||
System.out.println("You typed " + userResponse.charAt(0));
|
// Check if string == yes
|
||||||
// Kill the loop.
|
if (userResponse.toLowerCase().equals("no")) {
|
||||||
loopToggle = false;
|
System.out.println("You typed '" + userResponse + '\'');
|
||||||
} // Invalid input handling
|
// Kill the loop.
|
||||||
else {
|
loopToggle = false;
|
||||||
|
} else {
|
||||||
|
System.out.println("Invalid input! You entered '" + userResponse + '\'');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// User has responded with 'n'
|
||||||
|
System.out.println("You typed " + userResponse.charAt(0));
|
||||||
|
// Kill the loop.
|
||||||
|
loopToggle = false;
|
||||||
|
}
|
||||||
|
} else { // Invalid input handling
|
||||||
// Attempt to parse string as an integer.
|
// Attempt to parse string as an integer.
|
||||||
try {
|
try {
|
||||||
parseCheck = Integer.parseInt(userResponse);
|
parseCheck = Integer.parseInt(userResponse);
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user