This question already has an answer here:
I am trying to convert upper case letters to lower case and I get the following error:
animalException in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 6 at java.lang.String.charAt(Unknown Source) at newproject.chars.main(chars.java:11)
Here is my code:
public class chars { public static void main(String[] args) { String a = "AnImAl"; for(int b=0;b<=a.length();b++) { char c= a.charAt(b); if(c>=65 && c<=90) { c=(char)((c + 32)); } System.out.print(c); } }}
Could somebody explain to me why I get this error? Thanks in advance
I have to generate a random customer IDs in the format 'abc123DFG'. The first three letters have to be lowercase the next three are numbers and the next three uppercase letters. I could make it simple by using unicode but this would be too big of a code I think. I want to keep it short and efficient.
PS: I am actually a very bad programmer but somehow I made it through the first semester.
I am trying to convert a char element from an char *argv[] array to lowercase from uppercase without using a function. I want to add 32 to the ascii integer.
When I try to pass the variable as an argument, it will show the integer sum, but not the new lowercase character. Instead it shows the following output:
letter h, 104tolower: 136, �
Code:
int i = 0;for(i = 0; argv[1][i] != '\0'; i++) { char letter = argv[1][i]; printf("letter %c, %i\n", letter, letter); char tolower = argv[1][i]; int lowercase = tolower + 32; printf("tolower: %i, %c\n", lowercase, lowercase);}
Why is it printing a "?" char?
Is there a way to convert a string from uppercase, or even part uppercase to lowercase?
E.g. Kilometers --> kilometers.
I am trying to create a function in which after toLowerCase() input, will then capitalize the first letter in each element of an array.
function title_case ( String ) { var result = ""; var text = String.toLowerCase().split(" "); for (var i = 0; i < text.length; i++) { var c = text[i].charAt(0).toUpperCase(); result = result + c; } return result; }
Input:
document.write( title_case( "a kitty PUrrs") );
The resulting output of the current code is AKP. I'm trying to figure out a way to delete lowercase character with charAt(1) and then join() for the output if possible. Am I on the right track? I know there are simpler methods, but I'm trying to learn something along these lines.
Please note that by viewing our site you agree to our use of cookies (see Privacy for details). You will only see this message once.