![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Period multipliedBy() method in Java
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 follows
Example
import 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: " + p); System.out.println("The Period elements multiplied by 3 are: " + p.multipliedBy(3)); } }
Output
The Period is: P5Y9M4D The Period elements multiplied by 3 are: P15Y27M12D
Now let us understand the above program.
First the Period is displayed. Then an immutable copy of the Period where 3 is multiplied to the elements is obtained using the multipliedBy() method and this is displayed. A code snippet that demonstrates this is as follows:
String period = "P5Y9M4D"; Period p = Period.parse(period); System.out.println("The Period is: " + p); System.out.println("The Period elements multiplied by 3 are: " + p.multipliedBy(3));
Advertisements