我有一個腳本,它應(yīng)該采用一個由數(shù)字和字母組成的字符串,并將它們分解為ASCII/Hex相應(yīng)列下的值。它可以完美運行,直到我在字符串中的任何位置放置一個空格。它將正常打印所有內(nèi)容直到空格,然后中斷沒有錯誤。Ex. (works):kdillon76Ex. (does NOT work):kdillon 76在我的 For 循環(huán)中,我有一個 If 語句,說明如果字符是數(shù)字,則“執(zhí)行此操作”,然后是一個 Else 語句以涵蓋任何“其他”內(nèi)容。Else 語句不應(yīng)該能夠?qū)⒖崭褶D(zhuǎn)換為“32”ASCII 數(shù)字嗎?非常感謝任何和所有幫助! import java.util.*; // Load all Utility Classespublic class DKUnit3Ch12 { // Begin Class DKUnit3Ch12 public static void main(String[] args) { // Begin Main Scanner myScan = new Scanner(System.in); // Initialize the Scanner String myInput; // Define a new Variable System.out.print("Please enter a string of any length: "); //Print the text myInput = myScan.next(); // Define a new Variable with the next user input System.out.printf("%n%-8s%-16s%-16s%s%n", "Initial", "ASCII(char)", "ASCII(int)", "Hex"); // Print the labels with proper tablature for(int x = 0; x < myInput.length(); x++) { // Begin For Loop char myChar = myInput.charAt(x); // Define a new Variable based on position in index if(Character.isDigit(myChar)) { // Begin If Statement (if the character is a digit) System.out.printf("%-24s%-16d%02X%n", myChar, (int)myChar, (int)myChar); // Print the items with proper tablature including capitalized Hex } // End If Statement else { // Begin Else Statement (if the character is NOT a digit) System.out.printf("%-8s%-32d%02X%n", myChar, (int)myChar, (int)myChar); // Print the items with proper tablature including capitalized Hex } // End Else Statement } // End For Loop System.out.print("\nThank you for playing!"); // Print the text myScan.close(); // Close the Scanner } // End Main} // End Class DKUnit3Ch12
添加回答
舉報
0/150
提交
取消