Vikyath Ram has Published 178 Answers

Python program to reverse an array up to a given position

Vikyath Ram
Published on 26-Sep-2018 13:40:02
Here given user input array and the position of the array to be reverse.so our task is to reverse this array. We just reverse the sub array from [0 to (n-1)].ExampleInput : A=[3, 7, 6, 4, 1, 2] n=4 Output : [1, 4, 6, 7, 3, 2]AlgorithmStep 1: reverse list ... Read More

Python program to remove leading 0's from an IP address

Vikyath Ram
Published on 26-Sep-2018 11:07:15
IP address is given bellow, our task is to remove leading zeroes from the IP address. First we split the given string by “.” and then convert it to an integer and removes the leading zeroes then join back them to a string.ExampleInput : 200.040.009.400 Output : 200.40.9.400AlgorithmStep 1: Input ... Read More

Python program to generate all possible valid ID address from given string

Vikyath Ram
Published on 26-Sep-2018 10:51:09
String is given. String contains only digit. Our task is to check all possible valid IP address combinations. Here first we check the length of the string then split by ".". Then we check the different combination of ".". Example Input : "255011123222" It's not a valid IP ... Read More

Python program to find the size of the largest subset of anagram words

Vikyath Ram
Published on 26-Sep-2018 09:22:10
Given a lowercase array. Our task is to find the size of largest subset of string which are anagram of each other’s. Anagram of string means one string is an anagram of another if the second is simply a rearrangement of the first. Here we can solve this problem quickly ... Read More

Python program for the permutation of a given string inbuilt function in python

Vikyath Ram
Published on 26-Sep-2018 07:27:19
String is given. Our task is to display permutation of given string. Here solve this problem in python using inbuilt function permutations (iterable).ExampleInput : string = 'XYZ' Output : XYZ XZY YXZ YZX ZXY ZYXAlgorithmStep 1: given string. Step 2: Get all permutations of string. Step 3: print all permutations.Example ... Read More

How to initialize and compare strings?

Vikyath Ram
Published on 30-Aug-2018 07:24:44
Following example compares two strings by using str compareTo (string), str compareToIgnoreCase(String) and str compareTo(object string) of string class and returns the ascii difference of first odd characters of compared strings.Example Live Demopublic class StringCompareEmp{    public static void main(String args[]) {       String str = "Hello World";   ... Read More

Generating random numbers in Java

Vikyath Ram
Published on 14-Aug-2018 08:10:56
We can generate random numbers using three ways in Java.Using java.util.Random class − Object of Random class can be used to generate random numbers using nextInt(), nextDouble() etc. methods.Using java.lang.Math class − Math.random() methods returns a random double whenever invoked.Using java.util.concurrent.ThreadLocalRandom class − ThreadLocalRandom.current().nextInt() method and similar othjer methods return ... Read More

Flow control in a try catch finally in Java

Vikyath Ram
Published on 14-Aug-2018 07:29:50
A method catches an exception using a combination of the try and catch keywords. A try/catch block is placed around the code that might generate an exception. Code within a try/catch block is referred to as protected code, and the syntax for using try/catch looks like the following −Syntaxtry { ... Read More

Find free disk space using Java

Vikyath Ram
Published on 14-Aug-2018 07:04:14
java.io.File class provides following useful methods to figure out the free disk space available.Sr.No.Method & Description1public long getFreeSpace()Returns the number of unallocated bytes in the partition named by this abstract path name.2public long getTotalSpace()Returns the size of the partition named by this abstract pathname.3public long getUsableSpace()Returns the number of bytes ... Read More

Final static variables in Java

Vikyath Ram
Published on 14-Aug-2018 06:49:39
Final Static VariablesClass variables also known as static variables are declared with the static keyword in a class, but outside a method, constructor or a block.There would only be one copy of each class variable per class, regardless of how many objects are created from it.Static variables are normally declared ... Read More
Advertisements