loop and save letters in a string java

Solutions on MaxInterview for loop and save letters in a string java by the best coders in the world

showing results for - "loop and save letters in a string java"
Henri
28 Jul 2020
1StringBuilder phone = new StringBuilder();
2for (int i = 0; i < number.length(); i++){
3    if (Character.isLetter(number.charAt(i))){
4        phone.append(getNumber(Character.toUpperCase(number.charAt(i))));
5    }else{
6        phone.append(number.charAt(i));
7    }
8}
9
10System.out.println("Your number is " + phone.toString());
Cristóbal
15 Jun 2018
1    public static void main(String[] args){
2        Scanner input = new Scanner(System.in);
3
4            System.out.print("Enter phone number: ");
5            String number = input.nextLine();
6            String phone ="";
7
8            for (int i = 0; i < number.length(); i++){
9                if (Character.isLetter(number.charAt(i)))
10                    phone = getNumber(Character.toUpperCase(number.charAt(i)));
11                else
12                    number.charAt(i);
13            }
14            System.out.println("Your number is " + phone);              
15    }
16
17
18public static int getNumber(char uppercaseLetter){
19        if (uppercaseLetter >= 'W' && uppercaseLetter <= 'Z')
20            return 9;
21        else if (uppercaseLetter >= 'T' && uppercaseLetter < 'W')
22            return 8;
23        else if (uppercaseLetter >= 'P' && uppercaseLetter < 'T')
24            return 7;
25        else if (uppercaseLetter >= 'M' && uppercaseLetter < 'P')
26            return 6;
27        else if (uppercaseLetter >= 'J' && uppercaseLetter < 'M')
28            return 5;
29        else if (uppercaseLetter >= 'G' && uppercaseLetter < 'J')
30            return 4;
31        else if (uppercaseLetter >= 'D' && uppercaseLetter < 'G')
32            return 3;
33        else 
34            return 2;
35    }
36}
queries leading to this page
for loop for string in javajava string finish with lf 28 5cn 29java for loop stringfor loop in java string with changing charhow to create a loop that iterates through lettersjava while loop that prints the word depending on its lengthjava for loop with contains stringmake a while loop that takes the rightmost character and makes it another onehow to add a str to a str valuye after every looploop in java for stinghow to slice a string using a loop in pythonhot to create by looping the same string with increments the numbers javafor loop in string javahow to make a loop go for the length of a variable javahow to store a series of charecters with a for loop javamethod to remove all strings less then 5 characters in legnth java with a while loopindef of char in for of loopjava loop stringtake a string input in javahow to take input of a 2d array in java using scaner classjava while loop using a string and infor loop string length count javasplit string and store in dictionary pythonhow i can increment for loop for stringprint the string character in loop javahow to split and put elements in dictionary pythonint to string loop javahow to make string a loophow to make for loop for string typelength of string whith loop inv javaforlopp text in java java get a string out of a for loopstring value in a while condition javaget a string of the number loops in java how to add loop output in between a stringjava while loop using a string and intfor loop string javaloops using string javajava loop through characters in stringhow to create a loop that iterates through each string in the array and adds the user 27s text input to the end of each strinstring method to loop and and find a word javajava string loophow to grab a string using a for loopfor loop to run through stringusing different string in for loop javajava print string value in for loopfor loop characterjava char for loopshow to end while loop stringloop string javato measurements in a string for loop javajava print string letter by letter for loopstring letter loopdifferent string for loopfor loop in java to loop a letter 10 timesfor loop variation for stringhow to apply for loop on string in javaloops and strings javafor loop within stringjava loop string nameshow to take multiple string input and save in a dictionary in python how to find first character in for loop variablehow to make a loop that adds a number after everycharacter javahow to run a for loop long as stringhow to make a for loop start at the end of a string javahow to make loop that adds lettershow read faster int inputs in javastring loop in javastart loop at end of string javahow to loop a single letter in java 10 timesfor loop for string using uppercase characters over 10 lines in javas length in for loop javahow can you get 1 more character on each line in a for loop in javawhile loop to loop through stringphp make all the strings in an array uppercasehow to make a while statement with an int and stringhow to create a string using for loop in javahow to loopo a stringletters in a string for pythonjava contains inside loop but other numbersjava loop in a integer character by characterfor loop stringprint all substrings of a string using recursionhow to print string using for loop in javafor loop from string javafor loop in java stringloop a string in javacan you use i loops for stringsjava name string after for loop indexlooping character postition in string javafor loop that searches through a string javaloop as you get data between charactersfor loop for string javaloop for string javawhy is my i in the for loop a stringhow do take the first character of foor loop variablejava string name looploop through characters of string javaiterste a string in javajava add all char in a string and printloop through a string until it reaches a whitespace javatake textbox values and put them in string array and display them in listbox c 23how to loop string in javahow to make afor loop to check if a variable equals a string in a list javaloop and save letters in a string java