Write a Java method that prints a list of characters using the following header:public static void printChars (char ch1, char ch2, int numPerLine)This method prints chars between ch1 and ch2 (inclusive); the number of chars per-line is specified by int variable numPerLine. Then write and test Java programs that printa) characters from 1 to Z (uppercase), ten chars per line; b) all lowercase letters followed by all uppercase letters, 13 per line (Hint: you may want to call the method printChars twice in this second part)Consecutive characters on the same line should be separated by exactly one space.

Respuesta :

Answer:

The method and the test cases is as follows:

import java.util.*;

public class Main{

public static void printChars (char [tex]ch1[/tex], char [tex]ch2[/tex], int [tex]numPerLine[/tex]){

    int count = 0;

    for(char ch = ch1; ch<=ch2; ch++){

        System.out.print(ch+" ");

        count++;

        if(count == numPerLine){

            System.out.println();

            count = 0;         }     }

    System.out.println(); }

public static void main(String[] args) {

 printChars('1','Z',10);

 printChars('a','z',13);

 printChars('A','Z',13);

}}

Explanation:

See attachment for complete source file where comments are used as explanation

Ver imagen MrRoyal