ASDV-Java/Semester 1/Assignments/lab7_CalebFontenot/Not1.html

64 lines
3.5 KiB
HTML

2022-09-14 20:31:03 +07:00
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Not1.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}
.ST0 {color: #808080; font-family: monospace; font-weight: bold}
.comment {color: #808080}
.whitespace {color: #505050}
.string {color: #6a8759}
.number {color: #6897bb}
.literal {color: #cc7832}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">/home/caleb/NetBeansProjects/ADSV Java/lab7_CalebFontenot/src/main/java/com/calebfontenot/lab7_calebfontenot/Not1.java</td></tr></table>
<pre>
<span class="comment">/*</span>
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license</span>
<span class="comment"> * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template</span>
<span class="comment"> */</span>
<span class="literal">package</span> com.calebfontenot.lab7_calebfontenot;
<span class="literal">import</span> java.util.Scanner;
<span class="comment">/**</span>
<span class="comment"> *</span>
<span class="comment"> * </span><span class="ST0">@author</span> <span class="comment">caleb</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">class</span> Not1 {
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> main(String[] args)
{
System.out.print(<span class="string">&quot;</span><span class="string">Please enter a number between 0 and 10: </span><span class="string">&quot;</span>);
<span class="literal">int</span> number = <span class="literal">new</span> Scanner(System.in).nextInt();
<span class="comment">/* </span>
<span class="comment"> The ! is the NOT operator which reverses a boolean expression.</span>
<span class="comment"> If the expression is true, the not makes it false and vice-versa.</span>
<span class="comment"> the || is the OR operator which ORs 2 operands</span>
<span class="comment"> This is the equivalent AND1 by using OR and NOT</span>
<span class="comment"> 1. The &amp;&amp; is replaced by ||</span>
<span class="comment"> 2. The relational operators are reversed</span>
<span class="comment"> 3. There is a ! (NOT) outside the prenthesis</span>
<span class="comment"> */</span>
<span class="literal">if</span> ( ! (number &lt; <span class="number">0</span> || number &gt; <span class="number">10</span>) )
{
System.out.println(<span class="string">&quot;</span><span class="literal">\n</span><span class="string">Thank you for entering number </span><span class="string">&quot;</span> + number + <span class="string">&quot;</span><span class="string">!</span><span class="string">&quot;</span>);
}
<span class="literal">else</span> {
System.out.println(<span class="string">&quot;</span><span class="literal">\n</span><span class="string">&quot;</span> + number + <span class="string">&quot;</span><span class="string"> is not between 0 and 10! What&#39;s wrong with you man?</span><span class="string">&quot;</span>);
}
}
}
</pre></body>
</html>