Question

Write a function called isLowerCase that takes as a parameter a char and returns a boolean...

Write a function called isLowerCase that takes as a parameter a char and returns a boolean indicating whether the char is a lower-case (ASCII) letter.

Do not call one of the JDK's library functions, like Character.isLowerCase; instead, implement the function from scratch.

I just need a basic function using the most basic methods.

Homework Answers

Answer #1

import java.util.*;
import java.util.Scanner;
public class MyClass {
public static void main(String args[])
{
Scanner sc= new Scanner(System.in);
System.out.print("Enter a character: ");
char c = sc.next().charAt(0);
isLowerCase(c);
}
public static void isLowerCase(char c)
{
if(c == ' ' || c == '\t' || c == '\r' || c == '\n')
{
System.out.println("enter valid character");
}
else
{
  
if (c >= 'a' && c <= 'z')
{
System.out.println("The character entered is lowercase");
  
}
else
{
System.out.println("The character entered is not in lowercase");
}
}
  
}
}

Explanation:

import java.util.*; //This package includes all the libraries
import java.util.Scanner; //This package inludes library for Scanner class which helps to read input from user.
public class MyClass {
public static void main(String args[])
{
Scanner sc= new Scanner(System.in); // Scanner class to read the user input
System.out.print("Enter a character: ");
char c = sc.next().charAt(0); //This allows to compiler to read only one character that is at the index 0 even if user enters more then one character.
isLowerCase(c); //call to the isLowerCase (c) method by passing user inputted character as parameter
}
public static void isLowerCase(char c) //method to check if character is lowercase
{
if(c == ' ' || c == '\t' || c=='\r' || c == '\n')   //this makes the code to print enter valid character if user enters an empty space , tab, carriage return or a line
{
System.out.println("enter valid character");
}
else
{
  
if (c >= 'a' && c <= 'z') // this if condition compares the entered character on the basis of ascii value
{
System.out.println("The character entered is lowercase");
  
}
else
{
System.out.println("The character entered is not in lowercase");
}
}
  
}
}

Snapshot of the output obtained is shown below(I used an online compiler):

case1: When user enters character with first character as lowercase character

case2: When user enters character with first character as uppercase character

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a Python function that takes a filename as a parameter and returns the string 'rows'...
Write a Python function that takes a filename as a parameter and returns the string 'rows' if a file was written row by row, and 'columns' if the file was written column by column. You would call the function with a command like filetype = myfunc(filename).
1. Write a function called compute_discount which takes a float as the cost and a Boolean...
1. Write a function called compute_discount which takes a float as the cost and a Boolean value to indicate membership. If the customer is a member, give him/her a 10% discount. If the customer is not a member, she/he will not receive a discount. Give all customers a 5% discount, since it is Cyber Tuesday. Return the discounted cost. Do not prompt the user for input or print within the compute_discount function. Call the function from within main() and pass...
Write a function makeDoubles in c++, that takes an integer parameter called size and: allocates a...
Write a function makeDoubles in c++, that takes an integer parameter called size and: allocates a new array of that many double's initializes all elements to be 0 returns this array
A function called sum that takes n as a parameter and then returns the value of...
A function called sum that takes n as a parameter and then returns the value of 13+23+33+...+n3.Sample command => output:(display (sum 5)) => 225
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
Write a Python function that takes a list of integers as a parameter and returns the...
Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
C programming Write a function that takes in a 2D char array (string array) and return...
C programming Write a function that takes in a 2D char array (string array) and return a 1D char array with all the elements connected together Hint: strlen(-char*-) //returns the length of a string strcat(-char* accum-, something to add) //works like string+= in java
Write a Scheme function that takes a simple list of numbers as a parameter and returns...
Write a Scheme function that takes a simple list of numbers as a parameter and returns a list with the largest and smallest numbers in the input list.
Write a function named "replacement" that takes a string as a parameter and returns an identical...
Write a function named "replacement" that takes a string as a parameter and returns an identical string except with every instance of the character "i" replaced with the character "n python
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT