Question

In: Computer Science

TASK: Based upon the following code: import java.util.Scanner; // Import the Scanner class public class Main...

TASK:

Based upon the following code:

import java.util.Scanner; // Import the Scanner class

public class Main {

  public static void main( String[] args ) {

    Scanner myInput = new Scanner(System.in); // Create a Scanner object

    System.out.println("Enter (3) digits: ");

    int W = myInput.nextInt();

    int X = myInput.nextInt();

    int Y = myInput.nextInt();

  

  }

}

Use the tools described thus far to create additional code that will sort the integers in either monotonic ascending or descending order. Copy your code and output below:

import java.util.Scanner; // Import the Scanner class

public class Main {

  public static void main( String[] args ) {

    // Create a Scanner object

    Scanner myInput = new Scanner(System.in);

    // Accept the user's input

    System.out.println("Enter (3) digits: ");

    int W = myInput.nextInt();

    int X = myInput.nextInt();

    int Y = myInput.nextInt();

    // <TODO> - Sort the integers

    int first = 0;

    int second = 0;

    int third = 0;

    // Report the sorted numbers

    System.out.println( "The sorted values are:" );

    System.out.println( first + " " + second + " " + third);

  }

}

Solutions

Expert Solution

I WROTE THE CODE ALONG WITH THE COMMENTS

CODE:

import java.util.Scanner; // Import the Scanner class

public class Main {

public static void main( String[] args ) {

// Create a Scanner object

Scanner myInput = new Scanner(System.in);

// Accept the user's input

System.out.println("Enter (3) digits: ");

int W = myInput.nextInt();

int X = myInput.nextInt();

int Y = myInput.nextInt();

int first = 0;

int second = 0;

int third = 0;
  
if(W>X && W>Y) //condition for w is greather.
{
if(X>Y)
{
first=Y;
second=X;
third=W;
}
else
{
first=X;
second=Y;
third=W;
}
}
else if(X>W && X>Y) //condition for x is greather.
{
if(W>Y)
{
first=Y;
second=W;
third=X;
}
else
{
first=W;
second=Y;
third=X;
}
  
}
else
{
if(W>X)
{
first=X;
second=W;
third=Y;
}
else
{
first=W;
second=X;
third=Y;
}
}

// Report the sorted numbers

System.out.println( "The sorted values are:" );

System.out.println( first + " " + second + " " + third);

}

}

OUTPUT:

SCREENSHOT OF THE CODE:


Related Solutions

import java.lang.UnsupportedOperationException; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc...
import java.lang.UnsupportedOperationException; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in);    // parse the number of strings int numStrings = Integer.parseInt(sc.nextLine());    // parse each string String[] stringsArray = new String[numStrings]; for (int i = 0; i < numStrings; i++) { stringsArray[i] = sc.nextLine(); }    // print whether there are duplicates System.out.println(hasDuplicates(stringsArray)); }    private static boolean hasDuplicates(String[] stringsArray) { // TODO fill this in and remove the below line...
------------------------------------------------------------------------------------ import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input =...
------------------------------------------------------------------------------------ import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner input = new Scanner(System.in); int result = 0; System.out.print("Enter the first number: "); int x = input.nextInt(); System.out.print("Enter the second number: "); int y = input.nextInt(); System.out.println("operation type for + = 0"); System.out.println("operation type for - = 1"); System.out.println("operation type for * = 2"); System.out.print("Enter the operation type: "); int z = input.nextInt(); if(z==0){ result = x + y; System.out.println("The result is " + result); }else...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; public class Main { static Scanner sc=new Scanner(System.in);...
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Scanner; public class Main { static Scanner sc=new Scanner(System.in); static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); public static void main(String[] args) throws IOException { // TODO code application logic here System.out.print("Enter any String: "); String str = br.readLine(); System.out.print("\nEnter the Key: "); int key = sc.nextInt(); String encrypted = encrypt(str, key); System.out.println("\nEncrypted String is: " +encrypted); String decrypted = decrypt(encrypted, key); System.out.println("\nDecrypted String is: " +decrypted); System.out.println("\n"); } public static String encrypt(String str,...
Java Starter Code: import java.util.Scanner; public class GameScore { static Scanner keyboard = new Scanner(System.in); public...
Java Starter Code: import java.util.Scanner; public class GameScore { static Scanner keyboard = new Scanner(System.in); public static void main(String[] args) { int team1[] = new int[4]; int team2[] = new int[4]; for (int qtr = 0; qtr < 4; qtr++) { quarterScoring(team1, team2, qtr); } int team1Total = teamTotal(team1); int team2Total = teamTotal(team2); displayGameResults(team1, team2); if (team1Total > team2Total) { System.out.println("Team 1 has won the game!"); } else { System.out.println("Team 2 has won the game!"); } } static int teamTotal(int[]...
submit the following files: Main.java Consider the following code: import java.util.Scanner; public class Main { public...
submit the following files: Main.java Consider the following code: import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); String input = ""; System.out.println("Enter the first number: "); input = in.nextLine(); int a = 0; int b = 0; a = Integer.parseInt(input); System.out.println("Enter the second number: "); input = in.nextLine(); b = Integer.parseInt(input); int result = 0; result = a/b; System.out.println("a/b : " + result); } Copy the code to your Main.java file...
Consider the following code: import java.util.Scanner; public class Main {    public static void main(String[] args)...
Consider the following code: import java.util.Scanner; public class Main {    public static void main(String[] args) {    Scanner in = new Scanner(System.in); String input = ""; System.out.println("Enter the first number: ");    input = in.nextLine(); int a = 0; int b = 0;    a = Integer.parseInt(input);    System.out.println("Enter the second number: "); input = in.nextLine();    b = Integer.parseInt(input);    int result = 0; result = a/b;    System.out.println("a/b : " + result);    } Copy the code...
import chapter6.date.SimpleDate; import java.util.Scanner; public class SimpleDateTestDefault { public static void main(String[] args) { Scanner stdin...
import chapter6.date.SimpleDate; import java.util.Scanner; public class SimpleDateTestDefault { public static void main(String[] args) { Scanner stdin = new Scanner(System.in); SimpleDate d1 = new SimpleDate(); SimpleDate d2 = new SimpleDate(stdin.nextInt(), stdin.nextInt(), stdin.nextInt()); System.out.println(d1); System.out.println(d2); System.out.println(d1.before(d2)); System.out.println(d2.before(d1)); } } Implement SimpleDate class in chapter6.date package with the following attributes: day, (int type,  private) month, (int type,  private) year (int type,  private) The class should have the following methods: a constructor with three parameters: year, month, and day a constructor with no parameters which initialize the...
import java.util.Scanner; public class Squaring { public static void main(String[] args) { Scanner sc = new...
import java.util.Scanner; public class Squaring { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int num=0; String s = ""; while (true) { System.out.println("Enter an integer greater than 1: "); try { // reading input s = sc.nextLine(); // converting into int num = Integer.parseInt(s); break; } catch (Exception e) { System.out.println(s + " is not valid input."); } } // Now we have a valid number // putting into square int square = num; int count...
import java.util.Scanner; public class ZombieApocalypse{    public static void main(String[] args){    Scanner input = new...
import java.util.Scanner; public class ZombieApocalypse{    public static void main(String[] args){    Scanner input = new Scanner(System.in);           boolean gameOver = false; int colSize = 10; int rowSize= 10; String floorTile= "."; int playerX = 0; int playerY= 0; String playerTile="@"; int exitX= colSize-1; int exitY= rowSize-1; String exitTile="# "; int zombieX=5; int zombieY=5; // Defining Second Zombie int zombie2Y= 8; int zombie2X= 3; // Defining third zombie int zombie3Y= 1; int zombie3X= 7; String zombieTile="*"; String zombie2Tile="*";...
import java.util.Scanner; public class Grade { public static void main(String[] args) { Scanner scnr = new...
import java.util.Scanner; public class Grade { public static void main(String[] args) { Scanner scnr = new Scanner(System.in); // Reading score from user System.out.println("Enter the student's score:"); double score = scnr.nextDouble(); System.out.print("Grade:"); // Checking if score is less than 60 if(score<60){ System.out.println("F"); } // Checking if score is less than 70 else if(score<70){ System.out.println("D"); } // Checking if score is less than 80 else if(score<80){ System.out.println("C"); } // Checking if score is less than 90 else if(score<90){ System.out.println("B"); } // Checking...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT