The document describes a method that prints all characters in the ASCII table between two specified codes. It takes in two char parameters for the starting and ending codes. A for loop iterates from the start to end code, appending each character to a String. The String is returned and a newline is printed after calling the method with user input codes.
Use a for loop to print out all characters in the ascii table between.docx
1. Use a for loop to print out all characters in the ascii table between the codes: start and end
The method should print all the characters on one line and end with a newline.
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
/** Solve the method below **/
// take a look at the parameters char start and char end. You will use these
// while solving this challenge. They already have already been assigned values.
public static String printAscii(char start, char end){
for(start = 32; start <= end; i++){
}
return printAscii;
}
public static void main(String[] args) {
// Instantiate my Object of type Scanner
Scanner keyboard = new Scanner(System.in);
/* Here I'm doing a few things:
* 1. Using printf to print the String returned from your printAscii method
* 2. Calling your print Ascii method with two characters
* 3. Using the Scanner object to grab two tokens and using charAt(0) to get the first character
*/
char first = keyboard.next().charAt(0);
char second = keyboard.next().charAt(0);
System.out.printf("%s", printAscii(first, second));
keyboard.close(); // don't forget to close your Scanner!
}
}