ASDV-Java/Exams/Exam1Practice_CalebFontenot/DayOfTheWeek.html

87 lines
5.4 KiB
HTML
Raw Normal View History

2022-09-27 13:48:27 -05:00
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>DayOfTheWeek.java</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<style type="text/css">
<!--
body {color: #000000; background-color: #ffffff; font-family: monospace}
pre {color: #000000; background-color: #ffffff; font-family: monospace}
table {color: #404040; background-color: #e9e8e2; font-family: monospace}
.ST1 {color: #969696; font-family: monospace; font-weight: bold}
.ST2 {font-family: monospace; font-weight: bold}
.comment {color: #969696}
.ST3 {font-family: monospace; font-weight: bold; font-style: italic}
.ST4 {color: #ce54b8; font-family: monospace; font-style: italic}
.ST0 {color: #287bde}
.string {color: #1e9347}
.ST5 {color: #1e9347; font-family: monospace; font-weight: bold}
.literal {color: #336bdd}
-->
</style>
</head>
<body>
<table width="100%"><tr><td align="center">C:\Users\ar114\Documents\NetBeansProjects\Exam1_CalebFontenot\src\main\java\com\calebfontenot\exam1_calebfontenot\DayOfTheWeek.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> com.calebfontenot.exam1_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">ar114</span>
<span class="comment">*/</span>
<span class="literal">public</span> <span class="literal">class</span> <span class="ST2">DayOfTheWeek</span> {
<span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST3">main</span>(String[] args) {
Scanner input = <span class="literal">new</span> Scanner(System.<span class="ST4">in</span>);
System.<span class="ST4">out</span>.print(<span class="string">&quot;</span><span class="ST5">\n</span><span class="ST5">\n</span><span class="string"> Enter year (e.g. 2008): </span><span class="string">&quot;</span>);
<span class="literal">int</span> year = input.nextInt();
System.<span class="ST4">out</span>.print(<span class="string">&quot;</span><span class="string">Enter month 1-12: </span><span class="string">&quot;</span>);
<span class="literal">int</span> month = input.nextInt();
<span class="literal">if</span> (month == 1) {
month = 13;
year = year - 1;
}
<span class="literal">else</span> <span class="literal">if</span> (month == 2) {
month = 14;
year = year - 1;
}
System.<span class="ST4">out</span>.println(<span class="string">&quot;</span><span class="string">Enter the day of the month: 1-31: </span><span class="string">&quot;</span>);
<span class="literal">int</span> dayOfMonth = input.nextInt();
<span class="literal">int</span> j = year / 100;
<span class="literal">int</span> k = year % 100;
<span class="literal">int</span> dayOfWeek = (dayOfMonth
+ 26 * (month + 1) / 10 + k + k / 4 + j / 4 + 5 * j) % 7;
<span class="literal">if</span> (dayOfWeek == 0) {
System.<span class="ST4">out</span>.println(<span class="string">&quot;</span><span class="string">Day of the week is Saturday</span><span class="string">&quot;</span>);
}
<span class="literal">else</span> <span class="literal">if</span> (dayOfWeek == 1) {
System.<span class="ST4">out</span>.println(<span class="string">&quot;</span><span class="string">Day of the week is Sunday</span><span class="string">&quot;</span>);
}
<span class="literal">else</span> <span class="literal">if</span> (dayOfWeek == 2) {
System.<span class="ST4">out</span>.println(<span class="string">&quot;</span><span class="string">Day of the week is Monday</span><span class="string">&quot;</span>);
}
<span class="literal">else</span> <span class="literal">if</span> (dayOfWeek == 3) {
System.<span class="ST4">out</span>.println(<span class="string">&quot;</span><span class="string">Day of the week is Tuesday</span><span class="string">&quot;</span>);
}
<span class="literal">else</span> <span class="literal">if</span> (dayOfWeek == 4) {
System.<span class="ST4">out</span>.println(<span class="string">&quot;</span><span class="string">Day of the week is Wednesday</span><span class="string">&quot;</span>);
}
<span class="literal">else</span> <span class="literal">if</span> (dayOfWeek == 5) {
System.<span class="ST4">out</span>.println(<span class="string">&quot;</span><span class="string">Day of the week is Thursday</span><span class="string">&quot;</span>);
}
<span class="literal">else</span> <span class="literal">if</span> (dayOfWeek == 6) {
System.<span class="ST4">out</span>.println(<span class="string">&quot;</span><span class="string">Day of the week is Friday</span><span class="string">&quot;</span>);
}
}
}
</pre></body>
</html>