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="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ Explore the behavior of the `System.out.printf` function when displaying values

### **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.

# 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 FormatSpecifier.main(FormatSpecifier.java:7)
### **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
9 changes: 9 additions & 0 deletions src/FormatSpecifier.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
public class FormatSpecifier {
public static void main(String[] args) {
int intValue = 42;
double doubleValue = 3.14;

System.out.printf("Incorrect: %f%n", intValue);
System.out.printf("Incorrect: %d%n", doubleValue);
}
}
16 changes: 16 additions & 0 deletions src/TempConvert.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import java.util.Scanner;

public class TempConvert {
public static void main(String[] args) {
System.out.print("Enter a temperature in Celsius: ");

Scanner scanner = new Scanner(System.in);
double celsius = scanner.nextDouble();

double fahrenheit = celsius * 9/5 + 32;

System.out.printf("%.1f C = %.1f F\n", celsius, fahrenheit);

scanner.close();
}
}
19 changes: 19 additions & 0 deletions src/TimeConverter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import java.util.Scanner;

public class TimeConverter {
public static void main(String[] args) {

System.out.print("Enter a total number of seconds: ");

Scanner scanner = new Scanner(System.in);
int totalSeconds = scanner.nextInt();

int hours = totalSeconds / 3600;
int minutes = (totalSeconds % 3600) / 60;
int seconds = totalSeconds % 60;

System.out.printf("%d seconds = %d hours, %d minutes, and %d seconds\n", totalSeconds, hours, minutes, seconds);

scanner.close();
}
}