-
-
Save fado/7237429 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package qub.ac.uk.practical.week5; | |
// import scanner | |
import java.util.Scanner; | |
public class PracticalQuestionTwo { | |
/** | |
* A method for calling a case converter method | |
* @param args | |
*/ | |
public static void main(String[] args) { | |
// Declaring scanner | |
Scanner scanner = new Scanner(System.in); | |
// Declaring variables | |
String letter; | |
char firstChar; | |
// Getting and using user input | |
System.out.println("Please input a character: "); | |
letter = scanner.nextLine(); | |
firstChar = convertFromUpperToLower(letter.charAt(0)); | |
// Closing scanner | |
scanner.close(); | |
// Printing char with case corrected | |
System.out.println(firstChar); | |
} | |
/** | |
* A method which takes an upper case character | |
* and (if required) converts it to lower case. | |
* @return | |
*/ | |
public static char convertFromUpperToLower(char firstChar){ | |
if (Character.isLowerCase(firstChar)){ | |
return firstChar; | |
} else { | |
return Character.toLowerCase(firstChar); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment