Professional Documents
Culture Documents
TVL Comprog12 q3 m7
TVL Comprog12 q3 m7
MODULE 7
Computer Programming (Java) – Grade 12
Quarter 3 – Module 7: String Formatting in Java
Republic Act 8293, Section 176 states that no copyright shall subsist
in any work of the Government of the Philippines. However, prior approval of
the government agency or office wherein the work is created shall be
necessary for exploitation of such work for profit. Such agency or office may,
among other things, impose as a condition the payment of royalties.
Computer
Programming
QUARTER
+ 3
MODULE
Introductory Message
PRETEST
DIRECTIONS: Identify the following Java string Format. Choose your answer
inside the box.
Octal number Floating Point %d Unicode character
Hex String of value from hashcode() method
RECAP
shorturl.at/kqzRY
The more commonly known C-style format strings, used by the printf,
and Java’s String.format originated from BCPL (Basic Combined Programming
Language).
shorturl.at/kqzRY
Java wasn’t incepted with string.format. It took eight (8) years until the
release of Java 1.5 for it to be included.
The java string format() method returns the formatted string by given
locale, format and arguments. If you don't specify the locale in String.format()
method, it uses default locale by calling Locale.getDefault() method. The
format() method of java language is like sprintf() function in c language and
printf() method of java language.
Internal Implementation
shorturl.at/kqzRY
shorturl.at/kqzRY
Parameters –
locale : specifies the locale to be applied on the format () method.
format : format of the string.
args : arguments for the format string.
Throws –
NullPointerException : if format is null.
IllegalFormatException : if format is illegal or incompatible.
Java String format() Method Example
shorturl.at/kqzRY
Java String Format Specifiers
Here, we are providing a table of format specifiers supported by the Java
String.
shorturl.at/kqzRY
ACTIVITIES
DIRECTIONS: Create a simple code/program that will show an output of at
least 3 different Java String Format Specifiers which consist of Decimal
Floating point, Character and Integer Data type.
RUBRICS:
10 8 5 1
The program The program The program None matches
showed at least 3 showed at least showed at least the 3 different
different Java 2 different Java 1 different Java Java String
String Format String Format String Format Format.
WRAP-UP
DIRECTIONS: Identify the following Java String Formats that will show the
same output at the end. Write your answers on the space provided.
System.out.println(var1);
System.out.println(var2);
System.out.println(var3);
System.out.println(var4);
}
}
VALUING
DIRECTIONS: Answer the following questions below, and write your answer
in the space provided.
1. Based on what you have learned in this lesson, what do you think is
importance of Java String formatting in your program? And why do you
think you must consider these things in your program?
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
________________________________________________________________________
POST-TEST
Modified True or False.
DIRECTIONS: Write TRUE if the given words are correct but if it is false,
change the underlined word or group of words to make the statement true.
5. TRUE
4. %c 4. TRUE
3. %b 3. FALSE – DATE/TIME
2. %d 2. FALSE - %f
1. %s 1. FALSE – FORMAT
WRAP UP POST TEST
References
Websites:
Java String Format, Accessed Feb 2, 2021, 12:30:05 PM,
https://www.javatpoint.com/java-string-format