Compare and determine the smallest number

Assignment Help JAVA Programming
Reference no: EM13940711

Please explain the errors in the following Java code.

// AverageAndSmallest
// This program will get three numbers from the user
// and determine the smallest number and the average

import java.util.Scanner; // Scanner class used for getting user input

public class AverageAndSmallest
{
// The main method that begins execution of Java application
public static void main(String args[])
{
// variable declarations
int num1; // first number to compare
int num2; // second number to compare
int num3; // third number to compare
int smallest = 0; // variable to hold smallest
double average; // variable to hold average

// create Scanner to capture input from console
Scanner input = new Scanner(System.in);

// get user input, num1 and num2
System.out.print("Enter first number: ");
num1 = input.nextInt();
System.out.print("Enter second number: ");
num2 = input.nextInt();
System.out.print("Enter third number: ");
num3 = input.nextInt();

// Compare and determine the smallest
if (num1 > num2)
smallest = num2;
if (num1 < num2)
smallest = num1;
if (num3 < smallest)
smallest = num3;

// Calculate the average
average = num1 + num2 + num3 / 3;

// Display average and the smallest
System.out.printf("Average is %.2fn", average);
System.out.printf("Smallest is %dn", smallest);
}
}

Reference no: EM13940711

Questions Cloud

Explain the purpose of tqm : Define and explain the purpose of TQM. What elements within a manufacturing environment need to be reduced or eliminated as part of a Lean Manufacturing focus?
Risk management program for an organisation : This project entails you planning, conducting and evaluating a risk management program for an organisation. For the purpose of this project, the term organisation can include a small business, work team or division in a large organisation, sportin..
What fundamental assumptions of career criminal programs : What are some of the fundamental assumptions of career criminal programs? What limitations might these assumptions present in our efforts to identify and punish career criminals?
What is the slope of the cal : Draw the CAL of your portfolio on an expected return-standard deviation diagram. What is the slope of the CAL? Show the position of your client on your funds CAL
Compare and determine the smallest number : The main method that begins execution of Java application
Determine human resources requirements : Determine human resources requirements. Analyze the strategic and operational plans to determine human resource requirements and develop options for the delivery of human resource services.
Create a simple 2d predator-prey simulation. : The goal for this programming project is to create a simple 2D predator-prey simulation. In this simulation the prey are ants and the predators are doodlebugs. These critters live in a world composed of a 20x20 grid of cells.
What is ethical for the superintendent to do : Is it ethically justifiable to disregard the minor crime of prostitution if it is believed that it will assist in capturing more dangerous or violent criminals? Use relative statements and arguments to support your stand.
Calculate the vertical height raised : Calculate the vertical height raised, the final angular velocity of the drum, the work done, the input torque to the driving motor and the average power developed.

Reviews

Write a Review

JAVA Programming Questions & Answers

  What is difference between if statement and switch statement

What are the problems faced by Java programmers who don't use layout managers? What is the difference between an if statement and a switch statement?

  How do you manage cookies in applet-servlet communication

When you communicate with a servlet from an Applet or an application, how can you ensure that the session information is preserved? That is, how do you manage cookies in applet-servlet communication?

  Test plan outline a test plan for a substantial real-life

test plan outline a test plan for a substantial real-life system of your choosing. some possible examplesbullbaggage

  Java script program for song

Construct a JavaScript program that declares and prints an array that includes at least twenty of your favorite songs.

  A listener for the click events of a button

What happens if you fail to register an object as a listener for the click events of a button?

  Number of space characters in a string

Write a loop that counts the number of space characters in a string - You need to implement a program to find the number of spaces.

  Addressed with attributable risk

Which of the following questions is addressed with attributable risk?

  Output the number of tails using the constant array

Assume that this program compiles and runs. Assume that the user enters 5 0 (separated by a space) for input. What is the output. As always, be precise when showing your output. Output the number of Tails using the constant array for the "Tails" h..

  What fields and methods are inherited by which class

What java keyword is used in a class header when a class is defined as inheriting from an interface?

  Write a java program that uses the elapsed time

Write a Java program that uses the elapsed time for an event in second and then outputs the elapsed time in hours, minutes and seconds. (For case, if the desired time is 9630 seconds, then the output is 2: 40: 30)

  Write java applet for costco gas station

Write a java applet for costco gas station. The applet will first ask you whether you are a costco customer, then the grade of gas you want to use: grade 87, 89, or 91.

  Implements both the quicksort and mergesort algorithms

Write a program that correctly implements both the Quicksort and Mergesort algorithms. The program should generate an array of 500 random numbers in the 1-100 range. The program should sort the same set of numbers and keep time stamps of how long it ..

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd