Found 34494 Articles for Programming

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

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

119 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

441 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

Java program to remove items from Set

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

2K+ Views

A set in Java is modelled after the mathematical set and it cannot contain duplicate elements. The set interface contains the methods that are inherited from Collection. The method remove() removes the specified items from the set collection.A program that demonstrates the removal of items from Set using remove() is given as follows −Example Live Demoimport java.util.*; public class Example {    public static void main(String args[]) {       int arr[] = {5, 10, 10, 20, 30, 70, 89, 10, 111, 115};       Set set = new HashSet();       try {         ... Read More

Java Program to convert a Primitive Type Value to a String

Samual Sam
Updated on 26-Jun-2020 06:23:50

2K+ Views

For converting a primitive type value to a string in Java, use the valueOf() method.Let’s say we want to convert the following double primitive to string.double val4 = 8.34D;For that, use the valueOf() method. It converts it into a string.String str4 = String.valueOf(val4);Example Live Demopublic class Demo {    public static void main(String[] args) {       int val1 = 5;       char val2 = 'z';       float val3 = 9.56F;       double val4 = 8.34D;       System.out.println("Integer: "+val1);       System.out.println("Character: "+val2);       System.out.println("Float: "+val3);       ... Read More

Convert Char array to String in Java

karthikeya Boyini
Updated on 26-Jun-2020 06:24:54

586 Views

The valueOf() method is used in Java to convert char array to string.Here is our char array.// char array char[] c = {'p','q','r','s','t','u','v'};To convert it to string, use the valueOf() method.String str = String.valueOf(c);Example Live Demopublic class Demo {    public static void main(String[] args) {       // char array       char[] c = {'p','q','r','s','t','u','v'};       // converting to string       String str = String.valueOf(c);       System.out.println("String: "+str);    } }OutputString: pqrstuv

Python Parser for command line options

Chandu yadav
Updated on 26-Jun-2020 06:27:19

843 Views

Very often we need to pass arguments to Python script when executing from command line. However, the script raises exception when parameters needed are not provided in equal number or type or order. That’s where the need to properly parse the command line argument occurs.The argparse module provides tools for writing very easy to use command line interfaces. It handles how to parse the arguments collected in sys.argv list, automatically generate help and issues error message when invalid options are given.First step to desing the command line interface is to set up parser object. This is done by ArgumentParser() function ... Read More

Convert short to String in Java

Samual Sam
Updated on 26-Jun-2020 06:28:00

4K+ Views

The valueOf() method is used in Java to convert short to string.Let’s say we have the following short value.short val = 20;Converting the above short value to string.String.valueOf(val);Example Live Demopublic class Demo {    public static void main(String[] args) {       short shortVal = 55;       // converting short to String       String str = String.valueOf(shortVal);       System.out.println("String: "+str);    } }OutputString: 55

Advertisements