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

  Using the following data definition classpublic class

using the following data definition classpublic class circle private int radiuspublic circleint r radius rpublic int

  Create the benefit class

create the Benefit class

  Implement an iterative method with a for loop

Different scientists have developed Predator-Prey models to try to understand the interactions and foresee the evolution of the populations.

  Corrections as necessary and output screen snapshots

Submit all completed programs, with corrections as necessary and output screen snapshots, to demonstrate that they all perform properly to meet the specifications.

  Case study - greenhouse humidity control

The control system that will respond to sensor information to turn on/off a misting device, turn on/off a watering system and open/close ventilation windows.

  Programming exercises

Programming Exercises 1. Write an application named BadSubscriptCaught in which you declare an array of 10 first names. Write a try block in which you prompt the user for an integer and display the name in the requested position.

  Communication with an smtp server

Develop a graphical user interface based java program that can communicate with a real SMTP email server for sending emails

  Bull write a blog article for a coding and technical

bull write a blog article for a coding and technical community blog.bull the length of the article is to be between 500

  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 ..

  Presell a limited number of cinema tickets

Write an application to presell a limited number of cinema tickets. each buyer can buy as many as 4 tickets. No more than 100 tickets can be sold. Implement a program called TicketSeller that prompts the user for the desired number of tickets and the..

  Implement a distributed banking application

In the first part, you will implement a distributed banking application. The distributed bank has multiple branches. Every branch knows about all other branches.

  Compute the temperature in centigrade

Compute the temperature in Centigrade - Display the temperatures in both Centrigrade and Fahrenheit with appropriate labels, using the + operator to concatenate the labels with the variables

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