<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Problem1.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: Monospaced} pre {color: #000000; background-color: #ffffff; font-family: Monospaced} table {color: #000000; background-color: #e9e8e2; font-family: Monospaced} .ST0 {color: #969696; font-family: Monospaced; font-weight: bold} .ST1 {font-family: Monospaced; font-weight: bold} .comment {color: #969696} .ST2 {font-family: Monospaced; font-weight: bold; font-style: italic} .ST3 {color: #009900; font-family: Monospaced; font-style: italic} .literal {color: #0000e6} .ST4 {color: #ce7b00; font-family: Monospaced; font-weight: bold} .string {color: #ce7b00} --> </style> </head> <body> <table width="100%"><tr><td align="center">C:\Users\ar114\Documents\NetBeansProjects\Exam2_CalebFontenot\src\exam2_calebfontenot\Problem1.java</td></tr></table> <pre> <span class="comment">/*</span> <span class="comment"> * To change this license header, choose License Headers in Project Properties.</span> <span class="comment"> * To change this template file, choose Tools | Templates</span> <span class="comment"> * and open the template in the editor.</span> <span class="comment"> */</span> <span class="literal">package</span> exam2_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">ar114</span> <span class="comment">*/</span> <span class="literal">public</span> <span class="literal">class</span> <span class="ST1">Problem1</span> { <span class="comment">/**</span> <span class="comment"> * </span><span class="ST0">@param</span> args <span class="comment">the</span> <span class="comment">command</span> <span class="comment">line</span> <span class="comment">arguments</span> <span class="comment">*/</span> <span class="literal">public</span> <span class="literal">static</span> <span class="literal">void</span> <span class="ST2">main</span>(String[] args) { <span class="comment">// Define variables</span> <span class="literal">double</span> userInput = 0, average = 0; <span class="literal">int</span> timesRun = 0; <span class="comment">// Create scanner</span> Scanner input = <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="string">I will calculate the average of numbers you will enter. </span><span class="ST4">\n</span><span class="string">"</span>); <span class="comment">// While loop to grab inputs and calculate</span> <span class="literal">while</span> (userInput != -1) { System.<span class="ST3">out</span>.print(<span class="string">"</span><span class="string">Enter a positive number, or type -1 to quit: </span><span class="string">"</span>); userInput = input.nextDouble(); <span class="literal">if</span> (userInput != -1) { <span class="comment">// Calculate average</span> average += userInput; <span class="comment">// Increment timesRun</span> timesRun++; } } average = average / (<span class="literal">double</span>) timesRun; System.<span class="ST3">out</span>.println(<span class="string">"</span><span class="string">The average is: </span><span class="string">"</span> + average); } } </pre></body> </html>