
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 9150 Articles for Object Oriented Programming

985 Views
To check whether the entered character is a digit, whitespace, lowercase or uppercase, you need to check for the ASCII values.Let’s say we have a value in variable “val”, which is to be checked.For Lower Case.if(val >= 97 && val = 65 && val = 48 && val = 97 && val = 65 && val = 48 && val = 97 && val = 65 && val = 48 && val

4K+ Views
To check whether the entered value is whitespace or not in Java, use the Character.isWhitespace() method.We have a value to be checked.char val = ' ';Now let us use the Character.isWhitespace() method.if (Character.isWhitespace(val)) { System.out.println("Value is a Whitespace!"); } else { System.out.println("Value is not a Whitespace"); }Let us see the complete example now to check whether the entered value is whitespace or not in Java.Example Live Demopublic class Demo { public static void main(String []args) { char val =' '; System.out.println("Value: "+val); if (Character.isWhitespace(val)) { ... Read More

194 Views
The isLetterOrDigit() method in Java returns TRUE if the entered value is a letter or digit.We have the following character.char val ='P';Now, let us check for letter or digit using if-else decision-making statement.if (Character.isLetterOrDigit(val)) { System.out.println("Value is a letter or digit!"); } else { System.out.println("Value is neither a letter nor a digit!"); }The following is an example.Example Live Demopublic class Demo { public static void main(String []args) { char val ='P'; System.out.println("Value: "+val); if (Character.isLetterOrDigit(val)) { System.out.println("Value is a letter or digit!"); ... Read More

20K+ Views
Let’s say we have the following string, that has some letters and numbers.String str = "9as78";Now loop through the length of this string and use the Character.isLetter() method. Within that, use the charAt() method to check for each character/ number in the string.for (int i = 0; i < str.length(); i++) { if (Character.isLetter(str.charAt(i))) count++; }We have set a count variable above to get the length of the letters in the string.Here’s the complete example.Example Live Demopublic class Demo { public static void main(String []args) { String str = "9as78"; int count ... Read More

7K+ Views
To check whether the entered value is a letter or not in Java, use the Character.isLetter() method.We have a value to be checked.char val = 'D';Now let us use the Character.isLetter() method.if (Character.isLetter(val)) { System.out.println("Character is in Lowercase!"); }else { System.out.println("Character is in Uppercase!"); }Let us see the complete example now to check for letter.Example Live Demopublic class Demo { public static void main(String []args) { System.out.println("Checking whether the given value is a Letter or not..."); char val = 'D'; System.out.println("Value: "+val); if (Character.isLetter(val)) { ... Read More

2K+ Views
To validate if a String has only numbers, you can try the following codes. We have used the matches() method in Java here to check for number in a string.Example Live Demopublic class Demo { public static void main(String []args) { String str = "978"; System.out.println("Checking for string that has only numbers..."); System.out.println("String: "+str); if(str.matches("[0-9]+") && str.length() > 2) System.out.println("String has only numbers!"); else System.out.println("String consist of characters as well!"); } }OutputChecking for string that has only numbers... ... Read More

1K+ Views
In this article, we will subtract two integers and check if the result causes an overflow in Java. To check for Integer overflow, we need to check the Integer.MAX_VALUE with the subtracted integers result, Here, Integer.MAX_VALUE is the maximum value of an integer in Java. Let us see an example wherein integers are subtracted and if the result is more than Integer.MAX_VALUE, then an exception is thrown. Problem Statement Write a program in Java to subtract integers and check for overflow − Input val1 = 9898999val2 = 8784556 Output Value1: 9898999 Value2: 8784556 Subtraction Result: 1114443 Steps to subtract integers and check ... Read More

49K+ Views
To check whether a character is in Uppercase or not in Java, use the Character.isUpperCase() method.We have a character to be checked.char val = 'K';Now let us use the Character.isUpperCase() method.if (Character.isUpperCase(val)) { System.out.println("Character is in Uppercase!"); }else { System.out.println("Character is in Lowercase!"); }Let us see the complete example now to check for Uppercase in Java.Example Live Demopublic class Demo { public static void main(String []args) { System.out.println("Checking for Uppercase character..."); char val = 'K'; System.out.println("Character: "+val); if (Character.isUpperCase(val)) { System.out.println("Character is ... Read More

973 Views
In this article, we will learn to display printable characters in Java. The program uses ASCII code from 32 to 126, which correspond to printable symbols, numbers, and letters. Instead of using System.out.println(), we will use System.out.write() to print each character. Problem Statement Write a Java program that displays all printable characters by iterating through their ASCII values − Output Printable characters... ! " # $ % & '( ) * + , - . /0 1 2 3 4 5 6 78 9 : ; < = > ?@ A B C D E F GH I J K L M N OP Q R S T U V WX Y Z [ \ ] ^ _` a b c d e f gh i j k l m n op q r s t u v wx y z { | } ~ Steps to display printable characters Following are the steps to display printable characters − Start by printing the message "Printable characters...". Use a for loop to iterate over ASCII ... Read More

2K+ Views
To assign int value to a char variable in Java would consider the ASCII value and display the associated character/ digit.Here, we have a char.char val;Now assign int value to it.val = 77;Now, when you will print the value of “val”, it would display the character associate with the value (ASCII) 77.The following is the complete example.Example Live Demopublic class Demo { public static void main(String []args) { char val; val = 77; System.out.print("Value: "); System.out.println(val); } }OutputValue: M