Just in regards to the below code I am having an issue where everything is running fine but I am not getting the desired output.
The code should take user input and print it but with all the casing of letters reversed. However even though toggleCase works with no issue once the input is returned to toggleStringCase it reverts back to how it was before it was sent to toggleCase.
I am having trouble understanding why this is occuring.
Could someone please point me in the right direction.
Ideally I don't want you to tell me the answer but rather just help me go the right way to solve this.
package loopy;
import java.io.*;
public class loopy {
public static void main (String[] args) throws IOException {
// TODO: Use a loop to print every upper case letter
for (int i = 65; i < 91; i++) {
System.out.println((char)i);
}
// TODO: Get input from user. Print the same input back but with cases swapped. Use the helper functions below.
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
String input = in.readLine();
in.close();
toggleStringCase(input);
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
out.write(input);
out.close();
}
//Takes a single Character and reverse the case if it is a letter
private static char toggleCase(char c) {
int asciiValue = (int) c;
if (asciiValue > 96 && asciiValue < 123){
asciiValue = asciiValue - 32;
}
else if (asciiValue > 64 && asciiValue < 91){
asciiValue = asciiValue + 32;
}
else {
}
c = (char) asciiValue;
return c;
}
// Splits a string into individual characters that are sent to toggleCase to have their case changed
private static String toggleStringCase(String str) {
String reversedCase = new String();
for (int i = 0; i < str.length(); i++) {
char letter = str.charAt(i);
toggleCase(letter);
reversedCase = reversedCase + letter;
}
str = reversedCase;
return str;
}
}