Hey guys,
So I just started learning Java this year so you can say I'm fresh off the boat. Though I've learned programming concepts before (from Turing). Right now, I'm experiencing some difficulty in comparing/checking if a certain character is upper-case or lower-case.
This simple program just asks for the user to input a word/phrase and whatever letter is lower-case, I change it to upper-case and whatever letter is upper-case, I change it to lower-case.
import java.util.*; class UpperLower { public static void main() { String userInput; Scanner input = new Scanner (System.in ); System.out.println ("Please enter something...:"); userInput = input.nextLine(); String copyInput = userInput; for (int num = 0; num < userInput.length(); num++) { if (Character.isUpperCase(userInput.charAt(num))){ (userInput.substring(num)).toLowerCase(); } else { (userInput.substring(num)).toUpperCase(); } } System.out.println (userInput); } }
There seemed to be no compiler error however, when I tested my program, the letters' case were still unchanged. I'm not sure what is wrong with my code (perhaps it has to do with my if-condition?).
Please give this a try and see what is wrong. I really do appreciate your efforts, time and help. Thank you very much in advance!