diff --git a/.idea/misc.xml b/.idea/misc.xml index 639900d..172df7b 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/Java-Lab-003.iml b/Java-Lab-003.iml index b46c0dd..e1006ff 100644 --- a/Java-Lab-003.iml +++ b/Java-Lab-003.iml @@ -5,6 +5,7 @@ + \ No newline at end of file diff --git a/README.md b/README.md index cdcf86f..66a87f9 100644 --- a/README.md +++ b/README.md @@ -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.. diff --git a/src/FormatSpecifier.java b/src/FormatSpecifier.java new file mode 100644 index 0000000..02c2bf3 --- /dev/null +++ b/src/FormatSpecifier.java @@ -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); + } +} diff --git a/src/TempConvert.java b/src/TempConvert.java new file mode 100644 index 0000000..cfe9b65 --- /dev/null +++ b/src/TempConvert.java @@ -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(); + } +} diff --git a/src/TimeConverter.java b/src/TimeConverter.java new file mode 100644 index 0000000..8b46215 --- /dev/null +++ b/src/TimeConverter.java @@ -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(); + } +}