1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Bogdan [553]
4 years ago
4

Write a program whose inputs are three integers, and whose outputs are the largest of the three values and the smallest of the t

hree values. Ex: If the input is: 7 15 3 the output is: largest: 15 smallest: 3 Your program must define and call the following two methods. The method largestNumber() should return the largest number of the three input values. The method smallestNumber() should return the smallest number of the three input values. public static int largestNumber(int num1, int num2, int num3) public static int smallestNumber(int num1, int num2, int num3)
Computers and Technology
2 answers:
Alexeev081 [22]4 years ago
8 0

Answer:

#get input for numbers

a = int(input())

b = int(input())

c = int(input())

#set small to a

small = a

#if b is less then small

if b < small:

   small = b

   

#if c is less then small

if c < small:

   

#set small equall to c

small = c

#output the result

print(small)

Explanation:

Romashka [77]4 years ago
7 0

Answer:

The java program is as follows.

import java.util.Scanner;

import java.lang.*;

public class Numbers

{

//variables to hold three integers

static int num1, num2, num3;

//method to return largest of all three numbers

public static int largestNumber(int num1, int num2, int num3)

{

if(num1>num2 && num1>num3)

return num1;

else if(num2>num1 && num2>num3)

return num2;

else  

return num3;

}

//method to return smallest of all three numbers

public static int smallestNumber(int num1, int num2, int num3)

{

if(num1<num2 && num1<num3)

return num1;

else if(num2<num1 && num2<num3)

return num2;

else  

return num3;  

}

public static void main(String[] args)

{

Scanner sc = new Scanner(System.in);

System.out.print("Enter three numbers: ");

num1= sc.nextInt();

num2= sc.nextInt();

num3= sc.nextInt();

int largest = largestNumber(num1, num2, num3);

int smallest = smallestNumber(num1, num2, num3);

System.out.println("Largest number is "+ largest);

System.out.println("Smallest number is "+ smallest);

}

}

OUTPUT

Enter three numbers: 12 13 15

Largest number is 15

Smallest number is 12

Explanation:

1. Three integer variables are declared to hold the three user inputted numbers.  

2. The variables are declared static and declared at the class level.  

3. The method, largestNumber(), takes three numbers as parameters and returns the largest of all the three numbers. Hence, the return type of the method is int and declared as static.  

public static int largestNumber(int num1, int num2, int num3)  

4. The largest number is found using multiple if-else statements.  

5. The method, smallestNumber(), takes three numbers as parameters and returns the smallest of all the three numbers. Hence, the return type of the method is int and declared as static.  

public static int smallestNumber(int num1, int num2, int num3)  

6. The smallest number is found using multiple if-else statements.  

7. Inside main(), an object of Scanner class is created to enable user input.  

Scanner sc = new Scanner(System.in);  

8. The user is prompted to enter three numbers.  

9. The three numbers are passed as parameters to both the methods, largestNumber() and smallestNumber().  

10. Two integer variables, largest and smallest are declared. These variables hold the values returned from largestNumber() and smallestNumber() methods, respectively and displayed to the user.

You might be interested in
Imagine the user types in a complete sentence, but we want to read only the first word and place it in the String variable word.
Vladimir [108]

Answer:

import java.util.Scanner;

public class FirstWord {

   public static void main(String[] args) {

       //NOW YOU WANT TO COLLECT INPUTS FROM THE STUDENT OR USER

       //IMPORT THE SCANNER CLASS FIRST  outside your class

       // THEN YOU CREATE AN OBJECT OF THE SCANNER CLASS

       Scanner input = new Scanner(System.in);

       

       //CREATE A VARIABLE TO HOLD THE USER INPUT

       String text = input.nextLine();

       

       //The variable holder will be used to store characters from the for loop

       String holder="";

       

       //Create a for loop that loops through the user's input

       for(int i=0; i<text.length(); i++){

           //As the loop increases, we get the character in the user's input and store them one by one in the variable holder

           holder+=text.charAt(i);

           if(text.charAt(i)==' '){

               //If the loop encounters a space, it means a complete word has been gotten from the user's input

               //Then the break below Breaks the loop, and the loop stops running

               break;

           }

       }

       System.out.println(holder);

}

Explanation:

text.length() returns the length of the sequence of characters present in length

text.charAt(a number) Returns the char value at the specified index. An index ranges from 0 to length() - 1. The first char value of the sequence is at index 0, the next at index 1, and so on, as for array indexing.

Create a for loop

How does a for loop work?

It collects a starting point, an end point and an increment respectively....all these are passed in as arguments into the for loop

For example, the code above starts from 0, calculates the number of characters in the user's input and sets it as the end point, the loop runs from zero to the length of the text of the user...

Note: i++ in the loop is the increment, it means the loop increases by 1

8 0
4 years ago
Na2CO3 → Na2O + what
Katarina [22]

Answer:

CO3

Explanation:

6 0
3 years ago
Read 2 more answers
Which character formatting effect makes text appear in a small font size below the midpoint of a line of text
pav-90 [236]

Answer:

Superscript or Subscript

Explanation:

The superscript or the subscript is a type of character which is set a little lower or more than the normal line of type. And it is generally small as compared to the other texts. The subscript does appear at or less than the baseline, and the superscript is above. And for the superscript, you need to press the Ctrl + Shift + + ( press and at the same time also hold the Ctrl and the Shift, and finally press the +). And for the subscript, you need to press the Ctrl + Shift ++(Press and at the same time also hold the Ctrl. and finally press the =). And pressing the corresponding shortcut once again, you will be back to the normal text.

4 0
3 years ago
The file type blank identifies a word 2013 document
ZanzabumX [31]
Hey there! Hello!

The exclusive file type for Microsoft Word documents is .docx. You can see the attachment showing all the information you need to know about the example Word document I created. As long as you are using Word, the file type will be the same no matter what type of computer you're on or what it's running, so you don't need to worry about it being different for me on Mac than it might be for you on Windows. 

Hope this helped you out! Feel free to ask me any additional questions you may have. :-)

4 0
3 years ago
When you’re upset, you’re __ to get into a crash compared to when you’re not upset
Daniel [21]

Answer:

Your answer would be more likely.

Explanation:

When someone is upset and they are driving they usually have their music baring and the they can't hear their surroundings and all they can think about is what they are upset about so therefor they don't pay attention. Hope this helped! Have a great day! :)

7 0
4 years ago
Other questions:
  • Which sentence best describes an activity stream?
    10·2 answers
  • Operating system software allows you to use your fingers, a mouse or other pointing device to select screen controls, such as bu
    5·2 answers
  • Write the importance of cyber law? In point .<br>​
    10·2 answers
  • Mary is entering her senior year of college. She has a meeting on Friday with her advisor to discuss her career plans.Mary is al
    15·1 answer
  • Yolanda lost her left foot during her military service, but she has been issued a prosthetic that enables her to walk normally,
    13·1 answer
  • We can include following item(s) during configuration itemidentification:
    10·1 answer
  • Why are ethics important in PR?
    8·1 answer
  • What do the buttons on the paste options menu do
    11·1 answer
  • Calculate the cash available to retire debt for each of the six months. There is cash available to retire debt if there is a cas
    8·1 answer
  • How are 1gls different from 2gls​
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!