Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5b24056

Browse files
Demonstrating Overflow and Underflow
1 parent eecae54 commit 5b24056

File tree

6 files changed

+89
-0
lines changed

6 files changed

+89
-0
lines changed

‎Task-07/.gitignore‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
### IntelliJ IDEA ###
2+
out/
3+
!**/src/main/**/out/
4+
!**/src/test/**/out/
5+
6+
### Eclipse ###
7+
.apt_generated
8+
.classpath
9+
.factorypath
10+
.project
11+
.settings
12+
.springBeans
13+
.sts4-cache
14+
bin/
15+
!**/src/main/**/bin/
16+
!**/src/test/**/bin/
17+
18+
### NetBeans ###
19+
/nbproject/private/
20+
/nbbuild/
21+
/dist/
22+
/nbdist/
23+
/.nb-gradle/
24+
25+
### VS Code ###
26+
.vscode/
27+
28+
### Mac OS ###
29+
.DS_Store

‎Task-07/.idea/.gitignore‎

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Task-07/.idea/misc.xml‎

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Task-07/.idea/modules.xml‎

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Task-07/Task-07.iml‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>

‎Task-07/src/Main.java‎

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//Exercise 7: Demonstrating Overflow and Underflow
2+
//7. Task: Assign the value 2147483647 to an int variable and add 1. Print the result to observe overflow. Repeat for a byte variable.
3+
//o Expected Output:
4+
//Maximum value of int: [originally assigned value]
5+
//Maximum value of byte: [originally assigned value]
6+
//Overflow example with int: [Overflowed Value]
7+
//Overflow example with byte: [Overflowed Value]
8+
//Underflow example with int: [Underflow Value]
9+
//Underflow example with byte: [Underflow Value]
10+
11+
public class Main {
12+
public static void main(String[] args) {
13+
14+
int intMaxValue = 2147483647;
15+
byte byteMaxValue = Byte.MAX_VALUE;
16+
17+
int intMinValue = -2147483648;
18+
byte byteMinValue = Byte.MIN_VALUE;
19+
20+
System.out.println("Maximum value of int: " + intMaxValue);
21+
System.out.println("Maximum value of byte: " + byteMaxValue);
22+
23+
System.out.println("Overflow example with int: " + (intMaxValue + 1));
24+
System.out.println("Overflow example with byte: " + (byte)(byteMaxValue + 1));
25+
26+
System.out.println("Minimum value of int: " + intMinValue);
27+
System.out.println("Minimum value of byte: " + byteMinValue);
28+
29+
System.out.println("Underflow example with int: " + (intMinValue - 1));
30+
System.out.println("Underflow example with byte: " + (byte)(byteMinValue - 1));
31+
}
32+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /