71 lines
5.4 KiB
HTML
71 lines
5.4 KiB
HTML
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
|
|
<html>
|
|
<head>
|
|
<title>MenuFor.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}
|
|
pre {color: #a9b7c6; background-color: #2b2b2b; font-family: monospace}
|
|
table {color: #888888; background-color: #313335; font-family: monospace}
|
|
.literal {color: #cc7832}
|
|
.ST4 {font-family: monospace; font-style: italic}
|
|
.ST0 {color: #287bde}
|
|
.string {color: #6a8759}
|
|
.number {color: #6897bb}
|
|
.comment {color: #808080}
|
|
.whitespace {color: #505050}
|
|
.ST2 {color: #ffc66d; font-family: monospace; font-style: italic}
|
|
.ST3 {color: #9876aa; font-family: monospace; font-style: italic}
|
|
.ST1 {color: #808080; font-family: monospace; font-weight: bold}
|
|
-->
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<table width="100%"><tr><td align="center">/home/caleb/ASDV-Java/Assignments/lab11_ForLoop_CalebFontenot/src/lab11_forloop_calebfontenot/MenuFor.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_forloop_calebfontenot;
|
|
|
|
<span class="literal">import</span> java.util.Scanner;
|
|
|
|
<span class="comment">/**</span>
|
|
<span class="comment"> *</span>
|
|
<span class="comment"> * </span><span class="ST1">@author</span> <span class="comment">caleb</span>
|
|
<span class="comment">*/</span>
|
|
<span class="literal">public</span> <span class="literal">class</span> MenuFor {
|
|
|
|
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST2">main</span>(String[] args)
|
|
{
|
|
Scanner scan = <span class="literal">new</span> Scanner(System.<span class="ST3">in</span>);
|
|
|
|
System.<span class="ST3">out</span>.println(<span class="string">"</span><span class="literal">\n</span><span class="string">Q/q: to quit</span><span class="string">"</span>);
|
|
System.<span class="ST3">out</span>.println(<span class="string">"</span><span class="string">1: to calculate the square of a number</span><span class="string">"</span>);
|
|
System.<span class="ST3">out</span>.println(<span class="string">"</span><span class="string">2: to calculate the square root of a number</span><span class="string">"</span>);
|
|
<span class="literal">for</span> (String s = scan.next();
|
|
s.charAt(<span class="number">0</span>) != <span class="string">'</span><span class="string">Q</span><span class="string">'</span> && s.charAt(<span class="number">0</span>) != <span class="string">'</span><span class="string">q</span><span class="string">'</span>;
|
|
s = scan.next())
|
|
{
|
|
<span class="literal">if</span> (s.charAt(<span class="number">0</span>) == <span class="string">'</span><span class="string">1</span><span class="string">'</span> || s.charAt(<span class="number">0</span>) == <span class="string">'</span><span class="string">2</span><span class="string">'</span>) {
|
|
System.<span class="ST3">out</span>.println(<span class="string">"</span><span class="string">enter the number:</span><span class="string">"</span>);
|
|
<span class="literal">double</span> number = scan.nextDouble();
|
|
System.<span class="ST3">out</span>.println((s.charAt(<span class="number">0</span>) == <span class="string">'</span><span class="string">1</span><span class="string">'</span>)
|
|
? <span class="string">"</span><span class="string">the square : </span><span class="string">"</span> + (number * number)
|
|
: <span class="string">"</span><span class="string">the square root : </span><span class="string">"</span> + Math.<span class="ST4">pow</span>(number, <span class="number">0</span><span class="number">.5</span>));
|
|
} <span class="literal">else</span> <span class="literal">if</span> (s.charAt(<span class="number">0</span>) != <span class="string">'</span><span class="string">Q</span><span class="string">'</span> && s.charAt(<span class="number">0</span>) != <span class="string">'</span><span class="string">q</span><span class="string">'</span>) {
|
|
System.<span class="ST3">out</span>.println(<span class="string">"</span><span class="string">invalid character</span><span class="string">"</span>);
|
|
}
|
|
|
|
System.<span class="ST3">out</span>.println(<span class="string">"</span><span class="literal">\n</span><span class="string">Q/q: to quit</span><span class="string">"</span>);
|
|
System.<span class="ST3">out</span>.println(<span class="string">"</span><span class="string">1: to calculate the square of a number</span><span class="string">"</span>);
|
|
System.<span class="ST3">out</span>.println(<span class="string">"</span><span class="string">2: to calculate the square root of a number</span><span class="string">"</span>);
|
|
}
|
|
}
|
|
}
|
|
|
|
</pre></body>
|
|
</html>
|