[Go to site: main page, start]

0% found this document useful (0 votes)
11 views4 pages

Java Examples

The document contains multiple Java code examples demonstrating various programming concepts. It includes examples of comments, variables, arithmetic operators, relational operators, logical operators, assignment operators, increment/decrement operations, and type casting. Each example is structured with a main method that outputs relevant results to the console.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views4 pages

Java Examples

The document contains multiple Java code examples demonstrating various programming concepts. It includes examples of comments, variables, arithmetic operators, relational operators, logical operators, assignment operators, increment/decrement operations, and type casting. Each example is structured with a main method that outputs relevant results to the console.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Java Code Examples

[Link]

1 // This is a single-line comment


2 /* This is a
3 multi-line comment */
4 public class AComments {
5 public static void main(String[] args) {
6 [Link]("Comments Example");
7 }
8 }

[Link]

1 public class BVariables {


2 public static void main(String[] args) {
3 int number = 10;
4 String text = "Hello";
5 boolean isJavaFun = true;
6 [Link](number + ", " + text + ", " + isJavaFun);
7 }
8 }

[Link]

1 public class CJavaOperatorsAddition {


2 public static void main(String[] args) {
3 int a = 5;
4 int b = 10;
5 int sum = a + b;
6 [Link]("Sum: " + sum);
7 }
8 }
[Link]

1 public class DJavaOperatorsDivision {


2 public static void main(String[] args) {
3 int a = 10;
4 int b = 2;
5 int result = a / b;
6 [Link]("Division: " + result);
7 }
8 }

[Link]

1 public class EJavaOperatorsModulus {


2 public static void main(String[] args) {
3 int a = 10;
4 int b = 3;
5 int result = a % b;
6 [Link]("Modulus: " + result);
7 }
8 }

[Link]

1 public class FJavaRelationalOperators {


2 public static void main(String[] args) {
3 int a = 5;
4 int b = 10;
5 [Link](a < b); // true
6 [Link](a == b); // false
7 }
8 }
[Link]

1 public class GJavaLogicalOperator {


2 public static void main(String[] args) {
3 boolean x = true;
4 boolean y = false;
5 [Link](x && y); // false
6 [Link](x || y); // true
7 }
8 }

[Link]

1 public class HJavaAssignmentOperator {


2 public static void main(String[] args) {
3 int a = 5;
4 a += 3;
5 [Link]("a = " + a);
6 }
7 }

[Link]

1 public class IJavaIncrementDecrement {


2 public static void main(String[] args) {
3 int a = 5;
4 a++;
5 [Link]("Incremented: " + a);
6 a--;
7 [Link]("Decremented: " + a);
8 }
9 }
[Link]

1 public class JJavaCasting {


2 public static void main(String[] args) {
3 double d = 9.7;
4 int i = (int) d;
5 [Link]("Casted value: " + i);
6 }
7 }

You might also like