Skip to content

Instantly share code, notes, and snippets.

@fado
Forked from LordNairu/CaseConverter.java
Last active December 27, 2015 00:28
Show Gist options
  • Save fado/7237429 to your computer and use it in GitHub Desktop.
Save fado/7237429 to your computer and use it in GitHub Desktop.
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