Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Java-Lab-003.iml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="jdk" jdkName="openjdk-20" jdkType="JavaSDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,44 @@ Explore the behavior of the `System.out.printf` function when displaying values

**Printf Format Exploration:**
1. Use `printf` to display a value of type `int` using `%f`.
'''C:\Users\is-student\.jdks\openjdk-21.0.2\bin\java.exe "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2022.3.1\lib\idea_rt.jar=58713:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2022.3.1\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath C:\Users\is-student\IdeaProjectsq\Java-Lab-003\out\production\Java-Lab-003 Format
Exception in thread "main" java.util.IllegalFormatConversionException: f != java.lang.Integer
at java.base/java.util.Formatter$FormatSpecifier.failConversion(Formatter.java:4515)
at java.base/java.util.Formatter$FormatSpecifier.printFloat(Formatter.java:3079)
at java.base/java.util.Formatter$FormatSpecifier.print(Formatter.java:3027)
at java.base/java.util.Formatter.format(Formatter.java:2791)
at java.base/java.io.PrintStream.implFormat(PrintStream.java:1367)
at java.base/java.io.PrintStream.format(PrintStream.java:1346)
at java.base/java.io.PrintStream.printf(PrintStream.java:1245)
at Format.main(Format.java:8)'
2. Display a `double` using `%d`.
'''C:\Users\is-student\.jdks\openjdk-21.0.2\bin\java.exe "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2022.3.1\lib\idea_rt.jar=58788:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2022.3.1\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath C:\Users\is-student\IdeaProjectsq\Java-Lab-003\out\production\Java-Lab-003 Format
Exception in thread "main" java.util.IllegalFormatConversionException: d != java.lang.Double
at java.base/java.util.Formatter$FormatSpecifier.failConversion(Formatter.java:4515)
at java.base/java.util.Formatter$FormatSpecifier.printInteger(Formatter.java:3066)
at java.base/java.util.Formatter$FormatSpecifier.print(Formatter.java:3021)
at java.base/java.util.Formatter.format(Formatter.java:2791)
at java.base/java.io.PrintStream.implFormat(PrintStream.java:1367)
at java.base/java.io.PrintStream.format(PrintStream.java:1346)
at java.base/java.io.PrintStream.printf(PrintStream.java:1245)
at Format.main(Format.java:8)'
3. Try using two format specifiers but provide only one value.
'''C:\Users\is-student\.jdks\openjdk-21.0.2\bin\java.exe "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2022.3.1\lib\idea_rt.jar=58836:C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2022.3.1\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath C:\Users\is-student\IdeaProjectsq\Java-Lab-003\out\production\Java-Lab-003 Format
10.000000Exception in thread "main" java.util.IllegalFormatConversionException: d != java.lang.Double
at java.base/java.util.Formatter$FormatSpecifier.failConversion(Formatter.java:4515)
at java.base/java.util.Formatter$FormatSpecifier.printInteger(Formatter.java:3066)
at java.base/java.util.Formatter$FormatSpecifier.print(Formatter.java:3021)
at java.base/java.util.Formatter.format(Formatter.java:2791)
at java.base/java.io.PrintStream.implFormat(PrintStream.java:1367)
at java.base/java.io.PrintStream.format(PrintStream.java:1346)
at java.base/java.io.PrintStream.printf(PrintStream.java:1245)
at Format.main(Format.java:9)'


### **Instructions:**
For each of the issues above, screenshot and add the error images to this repo named **error01.png, error02.png, and error003.png** or simply edit this README.md and use markdown to list the error messages received.


### **Note:**
Your answers to this exercise should be added using Markdown into the project's `README.md` file so that they get committed with the project's code..

Expand Down
Binary file added img.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
30 changes: 30 additions & 0 deletions src/Format.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import java.util.Scanner;

public class Format {

public static void main(String[] args) {

Scanner s = new Scanner(System.in);
System.currentTimeMillis();
System.out.print("Enter a temperature in Celsius: ");
String input = s.nextLine();
double i = Double.parseDouble(input);
Double input1= (i*9/5)+32;
System.out.printf("Drgree Celsius : %.1f%% C ", i);
System.out.printf("and Drgree Fahrenheit : %.1f%% F%n", input1);

Scanner s1 = new Scanner(System.in);
System.currentTimeMillis();
System.out.print("Enter a total number of seconds: ");
String input2 = s1.nextLine();
int second = Integer.parseInt(input2);
int secondtohour= second/3600;
int secondtomin = secondtohour*60;
int secondtosecond=secondtomin*60;
System.out.printf("5000 second = %d hours, %d minutes, and %d seconds",secondtohour,secondtomin,secondtosecond);




}
}