Page 1 of 1

Problem Statement: Your task is to remove all spaces or dashes from a string credit CardNumber. For example, if credit C

Posted: Fri Jul 01, 2022 5:46 am
by answerhappygod
Problem Statement Your Task Is To Remove All Spaces Or Dashes From A String Credit Cardnumber For Example If Credit C 1
Problem Statement Your Task Is To Remove All Spaces Or Dashes From A String Credit Cardnumber For Example If Credit C 1 (30.13 KiB) Viewed 22 times
Problem Statement Your Task Is To Remove All Spaces Or Dashes From A String Credit Cardnumber For Example If Credit C 2
Problem Statement Your Task Is To Remove All Spaces Or Dashes From A String Credit Cardnumber For Example If Credit C 2 (21.39 KiB) Viewed 22 times
Problem Statement Your Task Is To Remove All Spaces Or Dashes From A String Credit Cardnumber For Example If Credit C 3
Problem Statement Your Task Is To Remove All Spaces Or Dashes From A String Credit Cardnumber For Example If Credit C 3 (19.71 KiB) Viewed 22 times
Problem Statement: Your task is to remove all spaces or dashes from a string credit CardNumber. For example, if credit CardNumber is "4123-5678-9812-3450", then you should set it to "4123567890123450". Credit Card Information (all fields are required) We Accept Credit Card Type: Credit Card Number Step 1 Decide what work must be done inside the loop. In the loop, we visit each character in turn. You can get the ith character as char ch credit CardNumber.charAt(1); If it is not a dash or space, we move on to the next character. If it is a dash or space, we remove the offending character i=0 While Set ch to the ith character of credit CardNumber. If ch is a space or dash Remove the character from credit CardNumber. Else (Do not enter spaces or deshes) Increment i. You may wonder how to remove a character from a string in Java. Here is the procedure for removing the character at position 1: Take the substrings that end before i and start after 1, and concatenate them. before after
4 public class CCNumber 5 { 6 7 8 9 10 11 12 13 14 15 16 17 18 19 Run CCNumber.java public static void main(String[] args) { String credit CardNumber= "4123-5678-9012-3450"; int i 0; while (i < credit CardNumber.length()) { char ch - credit CardNumber.charAt(i); if (ch, 1 ch - '-') { // Remove the character at position i String before credit CardNumber.substring(0, 1); String after credit CardNumber.substring(i+1): ww Load default template....
18 19 20 21 22 23 24 25 26 27 28 29 30 } 31 Run } } String before String after credit CardNumber.substring(0, i); credit CardNumber.substring(i+1); credit CardNumber = before + after; } else { } i++; System.out.println(creditCardNumber); 4123567890123450