I’m very new in Java and I got lab to do (is like a homework)
I’m trying to figure out how to write this method
public int checkCase(String data)
The question from the site:
Java is case sensitive … so just hitting the correct keys on the keyboard does not necessarily mean that you will get the correct variable or file name!!!!
Write the method that generates, stores (in an array) and lists (to standard output, one per line) ALL the possible names that can occur by pressing the correct keys but not necessarily the correct case (using the shift key or not) for an intended string whose value is read from standard input by the application and passed to this method as the parameter. For example, if the parameter value is “X.Y” this method will list the following (though not necessarily in this sequence):
X.y
X.Y
X>Y
X>y
x.Y
x.y
x>Y
x>y
You should provide for possible data lengths of 1-8 characters and any alphabetic keys or the period key.
I’m not trying to ask for the answer directly to my homework or anything, but I just would like to get some guide or advice from you guys who understand better or have better knowledge of Java so that I can complete my homework…. if my professor have made it clear in the class I wouldn’t bother asking here and waste anyone times in here, but really I’m lost at the moment.
Simplest method is loop through input string and for each character check its case using object wrapper under primitive
chartype – I meanCharacterclass. It has such method as:Character.isUpperCase(char ch)UPD:
accroding to updated question’s text, I have to change my answer.
Yes, I think you should use
Characterclass for this goals. It has such methods as:Character.toUpperCase(char ch)andCharacter.toLowerCase(char ch).You have to implement method, which will combine all possible cases for each char in the input string.
What about symbols
.->>– this case you have to consider as a special case in your program.