Question

In: Computer Science

Java language. Create the following Java command line iterator application Lab4. Pass in three arguments when...

Java language.

Create the following Java command line iterator application Lab4. Pass in three arguments when the program starts.

For example java Lab4 4 3 5

The command line arguments get passed into the main method as a String array in the variable object named args. Remember they get passed in as strings so you need to parse them into integers using the Integer.parseInt(args[X]) before you can treat them as integers. Create four sections that perform the following functions.

  1. Create a for loop iteration structure: loop the number of times of args[0] passed in, printing the counter value each time to the command line
  2. Create while loop iteration structure: loop the number of times of args[1] that was passed in, printing the counter value each time to the command line
  3. Create a do loop iteration structure: loop the number of times of args[2] that was passed in, printing the counter value each time to the command line
  4. Create a for each iteration structure to iterate through the args[] array printing the value in each element to the command line screen

Solutions

Expert Solution

Please find the code below:

Lab4.java

package classes6;

public class Lab4 {
   public static void main(String[] args) {

       int a = Integer.parseInt(args[0]);
       int b = Integer.parseInt(args[1]);
       int c = Integer.parseInt(args[2]);

       System.out.println("Printing counting of args[0] using for loop");
       for(int counter=1;counter<=a;counter++){
           System.out.println(counter);
       }

       int counter=1;
       System.out.println(" Printing counting of args[1] using while loop");
       while(counter<=b){
           System.out.println(counter);
           counter++;
       }


       counter=1;
       System.out.println(" Printing counting of args[2] using do-while loop");
       do{
           System.out.println(counter);
           counter++;
       }while(counter<=c);
      
       System.out.println(" Printing args using for each loop");
       for(String arg : args){
           System.out.println(arg);
       }

   }
}

output:


Related Solutions

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...
Write a Java application that accepts a bar code as a command line parameter and prints...
Write a Java application that accepts a bar code as a command line parameter and prints out the ZIP code. Assume that the bar code uses the symbols "|" and ":" for the long and short bars, respectively. Provide warnings on errors in the bar code specifying what exactly is wrong. The bar code input should be in the format specified in Problem 1, including the pair of the full bars at the beginning and at the end. Important: The...
(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.
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...
What is Last Pass? What is Java Language Applets?
What is Last Pass?What is Java Language Applets?What is Code Red?What is computer incident?
(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
Java Please comment code Create an Interactive JavaFX Application Create an application with the following controls:...
Java Please comment code Create an Interactive JavaFX Application Create an application with the following controls: A Label control with the following text displayed: "First Number:" A Label control with the following text displayed: "Second Number:" An empty TextField control beside the First Number label. An empty TextField control beside the Second Number label. Five buttons: Button 1 labeled + Button 2 labeled - Button 3 labeled * Button 4 labeled / Button 5 labeled = An empty Label control...
Answer the following in Java programming language Create a Java Program that will import a file...
Answer the following in Java programming language Create a Java Program that will import a file of contacts (contacts.txt) into a database (Just their first name and 10-digit phone number). The database should use the following class to represent each entry: public class contact {    String firstName;    String phoneNum; } Furthermore, your program should have two classes. (1) DatabaseDirectory.java:    This class should declare ArrayList as a private datafield to store objects into the database (theDatabase) with the...
write the following C program that ccepts command-line arguments following argv[0] — up to 20 decimal...
write the following C program that ccepts command-line arguments following argv[0] — up to 20 decimal integer literals. Each of these decimal integer literals will be expressed using decimal digits, only, and none of the decimal integer literals will be prefixed by a plus or minus sign. None of the decimal integer literals will be greater than ULONG_MAX. The program prints the integers in order, least-to-greates and also prints the sum of the integers.
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT