diff --git a/.idea/misc.xml b/.idea/misc.xml index 639900d..69ace3f 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..6b78e3a 100644 --- a/README.md +++ b/README.md @@ -12,8 +12,11 @@ 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`. +![img.png](img.png) 2. Display a `double` using `%d`. +![img_1.png](img_1.png) 3. Try using two format specifiers but provide only one value. +![img_2.png](img_2.png) ### **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. diff --git a/img.png b/img.png new file mode 100644 index 0000000..6fc9367 Binary files /dev/null and b/img.png differ diff --git a/img_1.png b/img_1.png new file mode 100644 index 0000000..e708c5f Binary files /dev/null and b/img_1.png differ diff --git a/img_2.png b/img_2.png new file mode 100644 index 0000000..adb5b92 Binary files /dev/null and b/img_2.png differ diff --git a/src/PartOne.java b/src/PartOne.java new file mode 100644 index 0000000..ff79e48 --- /dev/null +++ b/src/PartOne.java @@ -0,0 +1,13 @@ +public class PartOne { + public static void main(String[] args) { + + // 1. Use printf to display a value of type int using %f. + // System.out.printf("%f", 19); + + // 2. Display a double using %d. + // System.out.printf("%d", 2.718); + + // 3. Try using two format specifiers but provide only one value. + System.out.printf("%d %d", 19); + } +} diff --git a/src/TempConvert.java b/src/TempConvert.java new file mode 100644 index 0000000..87eec95 --- /dev/null +++ b/src/TempConvert.java @@ -0,0 +1,14 @@ +import java.util.Scanner; + +public class TempConvert { + public static void main(String[] args){ + + double f, c; + Scanner in = new Scanner(System.in); + + System.out.print("What is the temp in degrees Celsius? "); + c = in.nextDouble(); + f = c * 9.0/5.0 + 32.0; + System.out.printf("The temp in degrees Fahrenheit is %.1f", f); + } +} diff --git a/src/TimeConvert.java b/src/TimeConvert.java new file mode 100644 index 0000000..b111383 --- /dev/null +++ b/src/TimeConvert.java @@ -0,0 +1,22 @@ +import java.util.Scanner; + +public class TimeConvert { + public static void main(String[] args) { + + int sec, seconds, minutes, hours; + final int SEC_PER_HOUR = 3600; + final int SEC_PER_MIN = 60; + Scanner in = new Scanner(System.in); + + System.out.print("Enter the total number of seconds: "); + sec = in.nextInt(); + + // Convert 'sec' to hours, minutes, seconds: + hours = sec / SEC_PER_HOUR; + minutes = (sec % SEC_PER_HOUR) / SEC_PER_MIN; + seconds = sec % 60; + + System.out.printf("%d seconds = %d hour(s), %d minute(s), %d second(s).", sec, hours, minutes, seconds); + + } +}