Print Multiple Placeholders
This program prints multiple variables using formatted placeholders.
Problem Statement
Write a Java program that prints multiple variables using placeholders.
Source Code
| 1 | public class MultiplePlaceholders { |
| 2 | public static void main(String[] args) { |
| 3 | String course = "Java"; |
| 4 | int duration = 30; |
| 5 | double fee = 4999.50; |
| 6 | System.out.printf("Course: %s, Duration: %d days, Fee: %.2f - Eduinq", course, duration, fee); |
| 7 | } |
| 8 | } |
Program Output
Course: Java, Duration: 30 days, Fee: 4999.50 - Eduinq
Explanation
The %s placeholder is used for the string, %d for the integer, and %.2f for the decimal value formatted to two places, showing how multiple placeholders can format output neatly.