Question
Asked Feb 14, 2020
2 views

In java write a program that takes four int command-line arguments w, x, y, z,. define a boolean variable whose value is true if the four values are either in strictly acending order (w<x<y<z) or strictly descending order (w>x>y>z), and false otherwise, then display the boolean variable value.

Note: Do not use if statements on the program

Note: Assume that the inputs will always be integers

check_circle

Expert Answer

Step 1

The java program and its approach are given below: -

Approach: -  

  • Defining the main class and inside the main class defining the main() method.
  • Inside the main() method, declaring the variable as per the given instructions.
  • The variables store the value given as the command line arguments accordingly (description is given as the comments in the program).
  • The Boolean variable will store true if any of the conditions is valid that is either the command line arguments are given in the ascending or descending order otherwise false.
  • Displays the value stored in the Boolean variable.   
Step 2

Java program: -

//defining the main class

public class Main

{

    //defining the main method

    public static void main(String[] a)

    {

        //declaring the variables

        int w, x, y, z;

        //boolean variable

        boolean res;

        //the index of argument 'a' started from 0

        //command line arguments are of string types

        //parseInt() method is used to convert them into integers

        //the value at first index is stored in the variable w

        w = Integer.parseInt(a[0]);

        //the value at second index is stored in the variable x

        x = Integer.parseInt(a[1]);

        //the value at third index is stored in the variable y

        y = Integer.parseInt(a[2]);

        //the value at fourth index is stored in the variable z

        z = Integer.parseInt(a[3]);

        //comparing the values of varible w, x, y, z

        //res variable will store true if either of condition becomes true

        //otherwise false

        res = (w < x && x < y && y < z) || (w > x && x > y && y > z);

        //display the value of boolean varible either true or false

        System.out.println(res);

    }

}

Step 3

Program Screenshot with command-line arguments: -

Computer Science homework question answer, step 3, image 1

...

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Related Computer Science Q&A

Find answers to questions asked by student like you
Show more Q&A
add
question_answer

Q: What are Content Delivery Networks and what are their functions?

A: Click to see the answer

question_answer

Q: "What are a few things a good cyber security plan should include?

A: A good cyber security plan should include the following, A complete risk assessment of the user’s b...

question_answer

Q: Write a class in Java 1)  Consist of two methods: a. main b. printHigherThanAverage public stat...

A: In the main method – Make an object for a Scanner Declare an array to input the numbers of double t...

question_answer

Q: Draw the logic diagram for the following Boolean expressions. The diagram should correspond exactly ...

A: OR gate is used where + is provided in the boolean expression.AND gate is used where .(or multiplica...

question_answer

Q: No loops

A: The program is explained in detail with inlined comments. It uses the modulo operator % to find if t...

question_answer

Q: Statistics are often calculated with varying amounts of input data. Write a program that takes any n...

A: The below given python program will obey the following rubrics:Displaying message to user to enter i...

question_answer

Q: INPUT CONTROLS ANDNETWORKINGA global manufacturing company has over 100subsidiaries worldwide report...

A: Data security problems and control procedures: Problem 1:The headquarters received transmitted data ...

question_answer

Q: How do Virtual Network Functions in software provide flexibility, agility and implementation speed f...

A: Virtual Network Functions involve implementing specific network functions on top of networking infra...

question_answer

Q: What is the difference between Routing and Forwarding?

A: Routing A router is a procedure of choosing path along which the data can be moved from source to th...