Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How to write a program called CommandLine that uses a for-each loop to output each command line argument, one per line. For example, $ java

  • How to write a program called CommandLine that uses a for-each loop to output each command line argument, one per line. For example,

$ java CommandLine apple ball cat

apple

ball

cat

$ java CommandLine "Mr Wuf" "Mrs Wuf"

Mr Wuf

Mrs Wuf

How to write a program called Grades program in which the name of a student and one or more grades are entered on the command line. If there are less than 2 command line arguments, print a "Usage message" as shown below:

$ java Grades

Usage: java Grades name grade1 [grade2 ...]

$ java Grades Billy

Usage: java Grades name grade1 [grade2 ...]

If there are 2 or more command line arguments, you may assume that the first is the student's name and the following command line arguments are Strings that can be converted into integers. Output the student's name and the average of their grades (with 2 decimal places) as shown in the examples below:

$ java Grades Tonya 94

Tonya: 94.00

$ java Grades "Jesse Jones"98 78 89 70

Jesse Jones: 83.75

  • Complete the Append program below that contains an append() method that creates and returns a new array that contains the contents of the first array followed by the second array. :

import java.util.*;

public class Append {

public static void main(String[] args) {

Scanner scnr = new Scanner(System.in);

int[] a = {2, 4, 6};

int[] b = {1, 3};

int[] c = append(a, b);

System.out.println(Arrays.toString(c));

int[] d = {23, 89, 107, 54};

int[] e = {101, 42, 34, 67, 91, 99};

int[] f = append(d, e);

System.out.println(Arrays.toString(f));

}

public static int[] append(int[] first, int[] second) {

//Add code here

}

}

  • Here is the expected program output:

$ java Append

[2, 4, 6, 1, 3]

[23, 89, 107, 54, 101, 42, 34, 67, 91, 99]

Complete the MultiplicationTable program below that contains methods that create multiplication tables with a given number of rows and columns and prints them.

public class MultiplicationTable {

public static void main(String[] args) {

System.out.println();

int[][] smallTable = createMultiplicationTable(3);

printMultiplicationTable(smallTable);

System.out.println();

int[][] largeTable = createMultiplicationTable(10);

printMultiplicationTable(largeTable);

}

return a multiplication table witn n rows and n columns

//HINT: Set each array value to (i + 1) * (j + 1), where i and j

//represent the ith row and jth col.

public static int[][] createMultiplicationTable(int n) {

//Add code here

}

//Print multiplication table using %4d to print each value

public static void printMultiplicationTable(int[][] table) {

//Add code here

}

}

Here is the expected program output:

$ java MultiplicationTable

1 2 3

2 4 6

3 6 9

1 2 3 4 5 6 7 8 9 10

2 4 6 8 10 12 14 16 18 20

3 6 9 12 15 18 21 24 27 30

4 8 12 16 20 24 28 32 36 40

5 10 15 20 25 30 35 40 45 50

6 12 18 24 30 36 42 48 54 60

7 14 21 28 35 42 49 56 63 70

8 16 24 32 40 48 56 64 72 80

9 18 27 36 45 54 63 72 81 90

10 20 30 40 50 60 70 80 90 100

Step by Step Solution

There are 3 Steps involved in it

Step: 1

Sure Ill guide you through each of these programming tasks step by step Task 1 CommandLine Program This program uses a foreach loop to output each com... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Statistics For Managers Using Microsoft Excel

Authors: David M. Levine, David F. Stephan, Kathryn A. Szabat

7th Edition

978-0133061819, 133061817, 978-0133130805

More Books

Students also viewed these Programming questions