Found 9326 Articles for Object Oriented Programming

Java Program to add long integers and check for overflow

karthikeya Boyini
Updated on 26-Jun-2020 07:10:16

568 Views

To check for Long overflow, we need to check the Long.MAX_VALUE with the added long result. Here, Long.MAX_VALUE is the maximum value of Long type in Java.Let us see an example wherein long integers are added and if the result is more than the Long.MAX_VALUE, then an exception is thrown.The following is an example showing how to check for Long overflow.Example Live Demopublic class Demo {    public static void main(String[] args) {       long val1 = 80989;       long val2 = 87567;       System.out.println("Value1: "+val1);       System.out.println("Value2: "+val2);       long ... Read More

Java Program to check whether the character is ASCII 7 bit

Samual Sam
Updated on 26-Jun-2020 07:11:17

302 Views

To check whether the character is ASCII 7 bit or not, check whether given value’s ASCII value is less than 128 or not.Here, we have a character.char one = '-';Now, we have checked a condition with if-else for ASCII 7-bit character.if (c < 128) { System.out.println("Given value is ASCII 7 bit!"); } else {    System.out.println("Given value is not an ASCII 7 bit!"); }The following is an example wherein we check a character for ASCII 7-bit.Example Live Demopublic class Demo {    public static void main(String []args) {       char c = '-';       System.out.println("Given value = ... Read More

Java Program to check whether the entered value is ASCII 7-bit control character

karthikeya Boyini
Updated on 26-Jun-2020 07:13:37

218 Views

To check whether the entered value is ASCII 7-bit control character, check the characters ASCII value before 32 and 127. These are the control characters.Here, we have a character.char one = ' n ';Now, we have checked a condition with if-else to check for character less than 32 (ASCII) and equal to 127.if (one < 32 || one == 127) { System.out.println("Given value is a control character!"); } else {    System.out.println("Given value is not a control character!"); }Example Live Demopublic class Demo {    public static void main(String []args) {       char one = '';       ... Read More

Java Program to check whether the entered value is ASCII 7 bit alphabetic

Samual Sam
Updated on 26-Jun-2020 07:16:35

92 Views

To check whether the entered value is ASCII 7-bit alphabetic, check the character from ‘a’ to ‘z’ or ‘A’ to ‘Z’.Here, we have a character.char one = 'r';Now, we have checked a condition with if-else to check for character from ‘a’ to ‘z’ or ‘A’ to ‘Z’.if ((one >= 'A' && one = 'a' && one = 'A' && one = 'a' && one = 'A' && one = 'a' && one

Java Program to check whether the entered value is ASCII 7 bit alphabetic uppercase

karthikeya Boyini
Updated on 26-Jun-2020 07:22:15

52 Views

To check whether the entered value is ASCII 7-bit alphabetic uppercase, check the character from ‘A’ to ‘Z’.Here, we have a character.char one = 'T';Now, we have checked a condition with if-else to check for uppercase character from ‘A’ to ‘Z’if (one >= 'A' && one = 'A' && one = 'A' && one

Java Program to check whether the entered value is ASCII 7-bit alphabetic lowercase

Samual Sam
Updated on 26-Jun-2020 06:57:14

117 Views

To check whether the entered value is ASCII 7-bit alphabetic lowercase, check the character from ‘a’ to ‘z’.Here, we have a character.char one = 'm';Now, we have checked a condition with if-else to check for lowercase character from ‘a’ to ‘z’if (one >= 'a' && one = 'a' && one = 'a' && one

Compare two objects of Character type in Java

karthikeya Boyini
Updated on 26-Jun-2020 06:59:37

439 Views

To compare two objects of Character type in Java, use the compareTo() method.Firstly, we have created two Character type.Character one = new Character('m'); Character two = new Character('k');Now, to compare them, we have used the compareTo() method.int res = one.compareTo(two);The following is the example that compares character objects.Example Live Demopublic class Demo {    public static void main(String []args) {       Character one = new Character('m');       Character two = new Character('k');       System.out.println("Character object 1: "+one);       System.out.println("Character object 2: "+two);       int res = one.compareTo(two);       if ... Read More

Different Methods to find Prime Number in Java

Samual Sam
Updated on 26-Jun-2020 07:03:02

2K+ Views

A prime number is a number that is only divisible by one or itself. Some of the prime numbers are 2, 3, 5, 7, 11, 13 etc.Some of the different methods to find a prime number in Java are given as follows −Method 1 - Find if a number is prime without using a functionA program that finds if the given number is prime without using a function is given as follow −Example Live Demopublic class Example {    public static void main(String args[]) {       int num = 11, flag=0;       if(num == 0||num == 1) {          System.out.println( num + " is not a prime number");       } else {          for(int i = 2; i

Permutation and Combination in Java

karthikeya Boyini
Updated on 26-Jun-2020 07:04:26

4K+ Views

Permutation and Combination are a part of Combinatorics. Permutation is the different arrangements that a set of elements can make if the elements are taken one at a time, some at a time or all at a time. Combination is is the different ways of selecting elements if the elements are taken one at a time, some at a time or all at a time.An example of this is given as follows −Permutation = factorial(n) / factorial(n-r); Combination = factorial(n) / (factorial(r) * factorial(n-r)); n = 5 r = 3 Permutation = 60 Combination = 10A program that demonstrates this ... Read More

Stack in Java

Samual Sam
Updated on 26-Jun-2020 07:05:40

1K+ Views

A stack class is provided by the Java collection framework and it implements the Stack data structure. The stack implements LIFO i.e. Last In First Out. This means that the elements pushed last are the ones that are popped first.The following are some of the methods.Sr.NoMethods & Description1boolean empty()Tests if this stack is empty. Returns true if the stack is empty, and returns false if the stack contains elements.2Object peek( )Returns the element on the top of the stack, but does not remove it.3Object pop( )Returns the element on the top of the stack, removing it in the process.4Object push(Object ... Read More

Advertisements