Publicité
Use a for loop to print out all characters in the ascii table between.docx
Use a for loop to print out all characters in the ascii table between.docx
Prochain SlideShare
KOLEJ KOMUNITI - Sijil Aplikasi Perisian KomputerKOLEJ KOMUNITI - Sijil Aplikasi Perisian Komputer
Chargement dans ... 3
1 sur 2
Publicité

Contenu connexe

Similaire à Use a for loop to print out all characters in the ascii table between.docx(20)

Plus de kevin792(20)

Publicité

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! } }
  2. Solution Answer:) public static String printAscii(char start, char end) { for(int i= start; i<=end; i++) { printAscii = printAscii + new Character((char)i).toString(); } System.out.println("printAscii="+printAscii); return printAscii; }
Publicité