0% found this document useful (0 votes)
2 views3 pages

Java Examples

The document contains multiple Java code examples demonstrating various programming concepts, including comments, variables, arithmetic operations, relational and logical operators, assignment, increment/decrement, and type casting. Each example is encapsulated in a separate class with a main method that prints relevant output to the console. These examples serve as a practical guide for understanding basic Java syntax and functionality.
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)
2 views3 pages

Java Examples

The document contains multiple Java code examples demonstrating various programming concepts, including comments, variables, arithmetic operations, relational and logical operators, assignment, increment/decrement, and type casting. Each example is encapsulated in a separate class with a main method that prints relevant output to the console. These examples serve as a practical guide for understanding basic Java syntax and functionality.
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]

// This is a single-line comment


/* This is a
multi-line comment */
public class AComments {
public static void main(String[] args) {
// Print a message
[Link]("Hello, comments!");
}
}

[Link]

public class BVariables {


public static void main(String[] args) {
int age = 25;
double salary = 50000.50;
boolean isEmployed = true;
String name = "Alice";
[Link]("Name: " + name);
}
}

[Link]

public class CJavaOperatorsAddition {


public static void main(String[] args) {
int a = 10, b = 20;
int sum = a + b;
[Link]("Sum: " + sum);
}
}

[Link]

public class DJavaOperatorsDivision {


public static void main(String[] args) {
int a = 20, b = 4;
int result = a / b;
[Link]("Division: " + result);
}
}

[Link]

public class EJavaOperatorsModulus {


public static void main(String[] args) {
Java Code Examples

int a = 10, b = 3;
int remainder = a % b;
[Link]("Modulus: " + remainder);
}
}

[Link]

public class FJavaRelationalOperators {


public static void main(String[] args) {
int a = 5, b = 10;
[Link](a < b);
[Link](a == b);
}
}

[Link]

public class GJavaLogicalOperator {


public static void main(String[] args) {
boolean x = true, y = false;
[Link](x && y);
[Link](x || y);
}
}

[Link]

public class HJavaAssignmentOperator {


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

[Link]

public class IJavaIncrementDecrement {


public static void main(String[] args) {
int a = 5;
a++;
[Link]("Incremented: " + a);
a--;
[Link]("Decremented: " + a);
}
}
Java Code Examples

[Link]

public class JJavaCasting {


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

You might also like