Question

In: Computer Science

Q2.1 Write a Java program called Div that takes 2 (two) double command-line arguments as inputs,...

Q2.1 Write a Java program called Div that takes 2 (two) double command-line arguments as inputs, dividend and divisor (in that order) and performs a division operation. Your program either prints the quotient or an error if the divisor is zero. The divisor is the number you divide the dividend by.

public class Div

{

public static void main ( String[] args )

{

// WRITE YOUR CODE HERE

}

}

Q2.2

Write a Java program called IntCheck that examines the integer variable x, printing GT (greater than) if x is greater than 100, LT (less than) if x is less than 100 and EQ (equal) if x is 100.

public class IntCheck { public static void main ( String[] args ) { int x = Integer.parseInt(args[0]); // WRITE YOUR CODE HERE } }

Solutions

Expert Solution

Code for Q2.1 in java , given below :-


public class Div
{
   public static void main(String[] args) {
        double   ans;
       double dividend=1;
       double divisor=1;
      
        for(int i=0;i<args.length;i++)
        {
          dividend = Double.parseDouble(args[0]); // get command line argument dividend as a string and convert to double
          divisor = Double.parseDouble(args[1]);   //get command line argument divisor as a stringand convert to double
          System.out.println(args[i]);   //print dividend and divisor
        }
         
           if(divisor==0)
           {
               System.out.println("error, divisor is Zero!!!;"); //if divisor is zero
           }
           else if(divisor!=0)
           {
               ans=dividend/divisor;
               System.out.println(ans); //print answer
           }
   }
}

Code for Q2.2 in java , given below :-


public class IntCheck
{
   public static void main(String[] args) {
        int x=0;
       x = Integer.parseInt(args[0]); // get number as command line argument as a string and convert it into integer
      
     
           if(x==100)
           {
               System.out.println("EQ (equal)"); // if x if equal to 100
           }
           else if(x>100)
           {
             
               System.out.println("GT (greater than) "); // if x is greater than 100
           }
           else if(x<100)
           {
             
               System.out.println("LT (less than) "); // if x is less than 100
           }
   }
}

Screenshot of code and output:-


Related Solutions

Write a program that takes two command line arguments at the time the program is executed....
Write a program that takes two command line arguments at the time the program is executed. You may assume the user enters only decimal numeric characters. The input must be fully qualified, and the user should be notified of any value out of range for a 23-bit unsigned integer. The first argument is to be considered a data field. This data field is to be is operated upon by a mask defined by the second argument. The program should display...
Write a program that takes two command line arguments at the time the program is executed....
Write a program that takes two command line arguments at the time the program is executed. Both arguments are to be numerical values restricted to 22-bit unsigned integers. The input must be fully qualified, and the user should be notified of any errors with the input provided by the user. The first argument is to be considered a data field. This data field is to be is operated upon by a mask defined by the second argument. The program should...
program c Write a program called filesearch that accepts two command-line arguments: A string A filename...
program c Write a program called filesearch that accepts two command-line arguments: A string A filename If the user did not supply both arguments, the program should display an error message and exit. The program opens the given filename. Each line that contains the given string is displayed. Use the strstr function to search each line for the string. You may assume no line is longer than 255 characters. The matching lines are displayed to standard output (normally the screen).
write a program ordered.java Order check Write a program Ordered.java that takes four int command-line arguments...
write a program ordered.java Order check Write a program Ordered.java that takes four int command-line arguments w, x, y, and z. Define a boolean variable whose value is true if the four values are either in strictly ascending order (w < x < y < z) or strictly descending order (w > x > y > z), and false otherwise. Then, display the boolean variable value. NOTE 1: Do not use if statements on this program. NOTE 2: Assume that...
16.15 Lab 5: filter Name this program filter.c. The program takes two command line arguments: the...
16.15 Lab 5: filter Name this program filter.c. The program takes two command line arguments: the name of an input file and the name of an output file. The program should confirm the input and output files can be opened. If a file cannot be opened, print the error message Cannot open file '<filename>' where <filename> is the name of the file and return. fopen() will return 0 if it fails to open a file. Then, the program will read...
IN C LANGUAGE This program takes two command line arguments: an input filename a threshold Your...
IN C LANGUAGE This program takes two command line arguments: an input filename a threshold Your program will create two files: even.txt - contains all integers from the input file that are even and greater than the threshold odd.txt - contains all integers from the input file that are odd and greater than the threshold The input file will exist and only contain a set of integers. It will always be valid data. Output whitespace will be ignored. Name the...
(Triangle Inequality) Write a program triangle.py that takes three integers as command-line arguments and writes True...
(Triangle Inequality) Write a program triangle.py that takes three integers as command-line arguments and writes True if each one of them is less than or equal to the sum of the other two and False otherwise. This computation tests whether the three numbers could be the lengths of the sides of some triangle. $ python3 triangle.py 3 4 5 True $ python3 triangle.py 2 4 7 False
(Intro/Basic) JAVA Write a small program that gets some numbers as command-line arguments and finds the...
(Intro/Basic) JAVA Write a small program that gets some numbers as command-line arguments and finds the maximum of those numbers. You can assume that the user will provide some command-line arguments when running the program (so you don’t have to worry about what to do if the user doesn’t provide any arguments -- that won’t happen). Also, you can assume that all the command line arguments will be floating-point numbers, i.e., numbers with a decimal point, like 2.95.
Write a C program called test that takes one command line argument, an integer N. When...
Write a C program called test that takes one command line argument, an integer N. When we run test: ./test N the program will do this: the parent process forks N child processes each child process prints its process ID, exits the parent process waits for all child processes to exit, then exits
Write a program that prints the sum of its command-line arguments (assuming they are numbers). For...
Write a program that prints the sum of its command-line arguments (assuming they are numbers). For example, java Adder 3 2.5 -4.1 should print The sum is 1.4
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT