I have ~this~ code (not exactly, it’s edited for clarity*):
String method (String input){
Random rand = new Random();
String upper = new String();
String output = new String();
int index = 0;
input = input.toLowerCase(); upper = input.toUpperCase();
index = rand.nextInt(input.length()); output = input.charAt(0-(index-1)) + upper.charAt(index) + input.charAt((index + 1)-(input.length() - 1)); return (output);
}
It is supposed to capitalize a random letter in the string. When I compile it, I get this**:
class.java:17: error: incompatible types
output = input.charAt(0-(index-1)) + upper.charAt(index) + input.charAt((index + 1)-(input.length() - 1));
^
required: String
found: int
1 error
Anyone know what it’s referring to? I think it might have to do with the use of methods on methods***, as in I might have made an error somewhere with parenthases or order, but I can’t see an issue. Also, only the second “+” is an issue, not the first and the third, and the issue is with the “+”, not with the actual methods or variables according to the caret ("^")… -.-
I’d appreciate any answers!
(Oh, and are there “code” tags here? And can/should I use spoiler tags?)
*As in, the method name, class name, and variable names. I don’t actually hava a method called method in a class called class, with variables called input and output, they’re named things that make sense in context of the program in the real program
**I use notepad + CMD, and this is the CMD output.
*** like "input.charAt(input.length() - 1).toUpperCase();