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>
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
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.
13 changes: 13 additions & 0 deletions src/PartOne.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
14 changes: 14 additions & 0 deletions src/TempConvert.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
22 changes: 22 additions & 0 deletions src/TimeConvert.java
Original file line number Diff line number Diff line change
@@ -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);

}
}