FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
01-Core-Java/08-Java-Programs/016-Formatted-Output.java at main · shaikbasha-dev/01-Core-Java · GitHub
shaikbasha-dev
/
01-Core-Java
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
2
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
01-Core-Java
/
08-Java-Programs
/
016-Formatted-Output.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
98 lines (81 loc) · 2.98 KB
Breadcrumbs
01-Core-Java
/
08-Java-Programs
/
016-Formatted-Output.java
Copy path
File metadata and controls
98 lines (81 loc) · 2.98 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/*
* ============================================================================
* Program Name : Formatted Output
* File Name : 016-Formatted-Output.java
* Class Name : FormattedOutput
*
* Description:
* This program demonstrates how to display formatted output in Java
* using the printf() method. The printf() method allows developers to
* print values in a structured and readable format using format specifiers.
*
* Common Format Specifiers:
* %d - Integer
* %f - Floating-point Number
* %.2f - Floating-point Number (2 Decimal Places)
* %c - Character
* %s - String
* %b - Boolean
* %n - New Line
*
* Objective:
* - Understand formatted output using printf().
* - Learn commonly used format specifiers.
* - Display different data types in a formatted manner.
*
* Author : Shaik Mahaboob Basha
* Repository : 01-Core-Java
* Folder : 08-Java-Programs
* ============================================================================
*/
public
class
FormattedOutput
{
// The main() method is the entry point of every Java application.
public
static
void
main
(
String
[]
args
) {
// Declare and initialize an integer variable.
int
studentId
=
101
;
// Declare and initialize a String variable.
String
studentName
=
"Shaik Mahaboob Basha"
;
// Declare and initialize a double variable.
double
percentage
=
92.75
;
// Declare and initialize a character variable.
char
grade
=
'A'
;
// Declare and initialize a boolean variable.
boolean
isPassed
=
true
;
// Display a heading.
System
.
out
.
println
(
"========== Student Details =========="
);
// Print the integer using %d.
System
.
out
.
printf
(
"Student ID : %d%n"
,
studentId
);
// Print the String using %s.
System
.
out
.
printf
(
"Student Name : %s%n"
,
studentName
);
// Print the double value with two decimal places using %.2f.
System
.
out
.
printf
(
"Percentage : %.2f%n"
,
percentage
);
// Print the character using %c.
System
.
out
.
printf
(
"Grade : %c%n"
,
grade
);
// Print the boolean using %b.
System
.
out
.
printf
(
"Passed : %b%n"
,
isPassed
);
// Display another heading.
System
.
out
.
println
();
System
.
out
.
println
(
"========== Employee Details =========="
);
// Print multiple values using a single printf() statement.
System
.
out
.
printf
(
"ID: %d | Name: %s | Salary: %.2f | Grade: %c%n"
,
1001
,
"Rahul"
,
55000.75
,
'A'
);
/*
* Expected Output:
*
* ========== Student Details ==========
* Student ID : 101
* Student Name : Shaik Mahaboob Basha
* Percentage : 92.75
* Grade : A
* Passed : true
*
* ========== Employee Details ==========
* ID: 1001 | Name: Rahul | Salary: 55000.75 | Grade: A
*/
}
}
Back
|
FazBrowse Home
|
New Git URL