Question

Java 1. Implement a method that meets the following requirements: (a) Try to write this method...

Java

1. Implement a method that meets the following requirements:
(a) Try to write this method with as few lines of code as you can
(b) Sorts a group of three integers, x,y and z, into increasing order (they do not have to be in a
sequence).
(c) Assume the value in x is less than the value in z. You can also assume there are no duplicates
among x, y and z (none of them contain the same value)
(d) Prints a message each time the order of two elements are changed.
(e) Prints the list before and after sorting

Homework Answers

Answer #1

Hello,

Explanation

In the below screenshot, I showed the output and I displayed the message(Whenever the values are interchanged)

and each and every line in the code explained through comment lines.Hope you understand..!!

source code

import java.util.*;
import java.io.*;
public class HelloWorld{

public static void main(String []args){
int x;
int y;
int z;
Scanner sc=new Scanner(System.in);
//Reading the x and y and z values.
x=sc.nextInt();
y=sc.nextInt();
z=sc.nextInt();
System.out.println("--------------");
System.out.println("The values of x and y and z are displaying before sorting in increasing order");
System.out.println(x);
System.out.println(y);
System.out.println(z);
System.out.println("--------------");
//comparing x and y
if(x>y)
{
int k=y;
int k1=x;
//Here the message shown,When the values are interchanged
System.out.println("Here,The two values of"+x+"and"+y+"are interchanged");
x=k;
y=k1;
  
  
}
//comparing y and z
if(y>z)
{
int k=z;
int k1=y;
//Here the message shown,When the values are interchanged
System.out.println("Here,The two values of"+y+"and"+z+"are interchanged");
y=k;
z=k1;
  
}
System.out.println("--------------");
System.out.println("The values of x and y and z are displaying after sorting in increasing order");
System.out.println(x);
System.out.println(y);
System.out.println(z);
System.out.println("--------------");

  
}
}If you are satisfied with my Explanation. Please hit a like button.

Have a good Day...!!!!

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Implement a method that meets the following requirements using JAVA: (a) Calls mergesort to sort an...
Implement a method that meets the following requirements using JAVA: (a) Calls mergesort to sort an array/list of at least 5 integers (b) Prints the list before and after sorting.
JAVA Problem 1: Summing It Up Write a program, which takes two distinct integers separated by...
JAVA Problem 1: Summing It Up Write a program, which takes two distinct integers separated by space as input and prints the sum of all the integers between them, including the two given numbers. Note that the numbers can appear in either order. You may assume that both numbers are between –10, 000 and 10, 000. For example, if the input is as follows: 10 4 the output should be 49, since 10+9+8+7+6+5+4=49. Similarly, if the input is -3 10...
Intro to JAVA Problem 1: Summing It Up Write a program, which takes two distinct integers...
Intro to JAVA Problem 1: Summing It Up Write a program, which takes two distinct integers separated by space as input and prints the sum of all the integers between them, including the two given numbers. Note that the numbers can appear in either order. You may assume that both numbers are between –10, 000 and 10, 000. For example, if the input is as follows: 10 4 the output should be 49, since 10+9+8+7+6+5+4=49. Similarly, if the input is...
Java Please [(1)] A palindrome is a string that reads the same forwards as backwards. Using...
Java Please [(1)] A palindrome is a string that reads the same forwards as backwards. Using only a fixed number of stacks and queues, the stack and queue ADT functions, and a fixed number of int and char variables, write an algorithm to determine if a string is a palindrome. Assume that the string is read from standard input one character at a time. The algorithm should output true or false as appropriate [(2)] Let Q be a non-empty queue,...
The language is Java. Using a singly-linked list, implement the four queue methods enqueue(), dequeue(), peek(),...
The language is Java. Using a singly-linked list, implement the four queue methods enqueue(), dequeue(), peek(), and isEmpty(). For this assignment, enqueue() will be implemented in an unusual manner. That is, in the version of enqueue() we will use, if the element being processed is already in the queue then the element will not be enqueued and the equivalent element already in the queue will be placed at the end of the queue. Additionally, you must implement a circular queue....
Write a Java class called FlexArray that has/does the following: Has a private variable array that...
Write a Java class called FlexArray that has/does the following: Has a private variable array that holds integers as int[] array. Has a private variable capacity that is the maximum number of integers the array can hold. Has a private variable size that shows the number of currently occupied locations. Obviously, capacity >= size. Capacity tells you how many values the array can hold, not how many it has currently, which is available via the variable size. Has a default...
Implement a singly linked list having all unique elements with the following operations.I 0 x –...
Implement a singly linked list having all unique elements with the following operations.I 0 x – Inserts element x at the end. I 1 y x – If the element y exists, then insert element x after the element y, else insert element y before the existing element x. Assuming either the element x or the element y exists. I 2 z y x – Inserts element x in the middle of the elements z and y. The element z...
Using C++, Python, or Java, write a program that: In this programming exercise you will perform...
Using C++, Python, or Java, write a program that: In this programming exercise you will perform an empirical analysis of the QuickSort algorithm to study the actual average case behavior and compare it to the mathematically predicted behavior. That is, you will write a program that counts the number of comparisons performed by QuickSort on an array of a given size. You will run the program on a large number of arrays of a certain size and determine the average...
You are asked to implement a C++ class to model a sorted array of unsigned integers....
You are asked to implement a C++ class to model a sorted array of unsigned integers. The class is to be used in an embedded application that cannot assume the presence of the STL. The array has to be dynamically allocated in such a way that allows programmers using it to specify the required size. Your class should should: (1) provide the appropriate constructors and destructor; (2) provide methods for updating, and showing numbers in/to the array (e.g., to be...
JAVA Bike shares are becoming increasingly common in cities in the United States. Commuters have been...
JAVA Bike shares are becoming increasingly common in cities in the United States. Commuters have been using bike sharing as a method of transportation for the flexibility, cost savings, exercise, and a myriad of other benefits. While being quite successful, many bike shares are still relatively new and have room for optimization. To help with the optimization process, we want to analyze bike share data from the city of Los Angeles. The first step of the process is to collect...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT