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>
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ For each of the issues above, screenshot and add the error images to this repo n

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

Errors in Printf 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 Printf.main(Printf.java:5)

---

Expand Down
9 changes: 9 additions & 0 deletions src/Printf.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
public class Printf {
public static void main(String[] args) {
int intValue = 10;
double doubleValue = 5.75;
System.out.printf("Displaying an int using %%f: %f\n", intValue);
System.out.printf("Displaying a double using %%d: %d\n", doubleValue);
System.out.printf("Providing only one value for two format specifiers: %d %f\n", intValue);
}
}
14 changes: 14 additions & 0 deletions src/SecondsToTimeConverter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import java.util.Scanner;
public class SecondsToTimeConverter {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a total number of seconds: ");
int totalSeconds = scanner.nextInt();
int hours = totalSeconds / 3600;
int remainingSeconds = totalSeconds % 3600;
int minutes = remainingSeconds / 60;
int seconds = remainingSeconds % 60;
System.out.printf("%d seconds = %d hours, %d minutes, and %d seconds\n", totalSeconds, hours, minutes, seconds);
scanner.close();
}
}
11 changes: 11 additions & 0 deletions src/TempConvert.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import java.util.Scanner;
public class TempConvert {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a temperature in Celsius: ");
double celsius = scanner.nextDouble();
double fahrenheit = celsius * 9 / 5 + 32;
System.out.printf("%.1f C = %.1f F\n", celsius, fahrenheit);
scanner.close();
}
}