Found 34473 Articles for Programming

Period multipliedBy() method in Java

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

49 Views

An immutable copy of a Period where all the Period elements are multiplied by a value can be obtained using the method multipliedBy() in the Period class in Java. This method requires a single parameter i.e. the value which is to be multiplied and it returns the immutable copy of the Period which is multiplied by a value.A program that demonstrates this is given as followsExample Live Demoimport java.time.Period; public class Demo {    public static void main(String[] args) {       String period = "P5Y9M4D";       Period p = Period.parse(period);       System.out.println("The Period is: " ... Read More

C++ Program to Perform Quick Sort on Large Number of Elements

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

330 Views

The quicksort technique is done by separating the list into two parts. Initially a pivot element is chosen by partitioning algorithm. The left part of the pivot holds the smaller values than pivot, and right part holds the larger value. After partitioning, each separate lists are partitioned using same procedure.Here we are considering a large array (nearly 100 elements) to sort. We are taking some numbers then shuffling them in randomized order to make them unsorted. Then sort using quicksort technique.The complexity of Quicksort TechniqueTime Complexity − O(n log n) for best case and average case, O(n2) for worst case.Space ... Read More

Period from() method in Java

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

64 Views

An instance of a Period object can be obtained from a Temporal object using the from() method in the Period class in Java. This method requires a single parameter i.e. the TemporalAmount and it returns the Period object that is obtained.A program that demonstrates this is given as followsExample Live Demoimport java.time.Period; public class Demo {    public static void main(String[] args) {       int days = 20;       int months = 11;       int years = 3;       Period p = Period.from(Period.of(years, months, days));       System.out.println("The Period is: " + ... Read More

Period parse() method in Java

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

487 Views

The Period instance can be obtained from a string value using the parse() method in the Period class in Java. This method requires a single parameter i.e. the string which is to be parsed. This string cannot be null. Also, it returns the Period instance obtained from the string value that was passed as a parameter.A program that demonstrates this is given as follows:Example Live Demoimport java.time.Period; public class Demo {    public static void main(String[] args) {       String period = "P5Y7M15D";       Period p = Period.parse(period);       System.out.println("The Period is: " + p); ... Read More

Period of() method in Java

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

67 Views

The Period can be obtained with the given number of days, months and years using the of() method in the Period class in Java. This method requires a 3 parameters i.e. the number of days, the number of months and the number of years. Also, it returns the Period object with the given number of days, months and years.A program that demonstrates this is given as followsExample Live Demoimport java.time.Period; public class Demo {    public static void main(String[] args) {       int days = 20;       int months = 11;       int years = ... Read More

Period toTotalMonths() method in Java

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

33 Views

The total number of months for a particular Period can be obtained using the toTotalMonths() method in the Period class in Java. This method requires no parameters and it returns the total number of months in the Period in the form of a long value.A program that demonstrates this is given as followsExample Live Demoimport java.time.Period; public class Demo {    public static void main(String[] args) {       String period = "P2Y1M15D";       Period p = Period.parse(period);       System.out.println("The Period is: " + p);       System.out.println("The total number of months are: " + ... Read More

C++ Program to Implement Sorting of Less than 100 Numbers in O(n) Complexity

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25

240 Views

To sort some small numbers in linear time we can use the counting sort technique.Counting sort is a stable sorting technique, which is used to sort objects according the keys that are small numbers. It counts the number of keys whose key values are same. This sorting technique is efficient when difference between different keys are not so big, otherwise it can increase the space complexity.The complexity of counting Sort TechniqueTime Complexity: O(n + r)Space Complexity: O(n + r)Input − A list of unsorted data: 2 5 6 2 3 10 3 6 7 8 Output − Array after Sorting: ... Read More

C++ Program to Implement Quick Sort Using Randomization

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

3K+ Views

The quicksort technique is done by separating the list into two parts. Initially a pivot element is chosen by partitioning algorithm. The left part of the pivot holds the smaller values than pivot, and right part holds the larger value. After partitioning, each separate lists are partitioned using same procedure.In this case we are choosing the pivot element randomly. After choosing the pivot, we are doing the partitioning, then sort the array recursively.The complexity of Quicksort TechniqueTime Complexity − O(n log n) for best case and average case, O(n2) for worst case.Space Complexity − O(log n)Input − The unsorted list: 90 ... Read More

Period isZero() method in Java

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

114 Views

It can be checked if the days, months and years in the Period are zero or not using the isZero() method in the Period class in Java. This method requires no parameters. Also, it returns true if the days, months and years in the Period are zero and false otherwise.A program that demonstrates this is given as followsExample Live Demoimport java.time.Period; public class Demo {    public static void main(String[] args) {       String period = "P0Y0M0D";       Period p = Period.parse(period);       System.out.println("The Period is: " + p);       System.out.println("The days, months ... Read More

Period getYears() method in Java

Daniol Thomas
Updated on 30-Jul-2019 22:30:25

173 Views

The number of years for a particular Period can be obtained using the getYears() method in the Period class in Java. This method requires no parameters and it returns the number of years in the Period.A program that demonstrates this is given as followsExample Live Demoimport java.time.Period; public class Demo {    public static void main(String[] args) {       String period = "P5Y7M15D";       Period p = Period.parse(period);       System.out.println("The Period is: " + p);       System.out.println("The number of years are: " + p.getYears());    } }OutputThe Period is: P5Y7M15D The number of ... Read More

Advertisements