0% found this document useful (0 votes)
0 views2 pages

Java Fundamentals DataTypes Operators

The document provides Java programming examples covering data types, global variables, arithmetic operations, and swapping techniques. It includes sample code for swapping values using a third variable and arithmetic operations, as well as a section with multiple-choice questions related to operators. The examples illustrate fundamental Java concepts suitable for beginners.

Uploaded by

ARVIND VENKAT
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)
0 views2 pages

Java Fundamentals DataTypes Operators

The document provides Java programming examples covering data types, global variables, arithmetic operations, and swapping techniques. It includes sample code for swapping values using a third variable and arithmetic operations, as well as a section with multiple-choice questions related to operators. The examples illustrate fundamental Java concepts suitable for beginners.

Uploaded by

ARVIND VENKAT
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
You are on page 1/ 2

Java Fundamentals: Programs and Concepts

Data Types - Swapping using third variable

public class SwapUsingThird {


public static void main(String[] args) {
int a = 10, b = 20, temp;
temp = a;
a = b;
b = temp;
System.out.println("After Swapping: a = " + a + ", b = " + b);
}
}

Data Types - Global variable and print in main

public class GlobalVariable {


static int globalNumber = 50; // Global variable
public static void main(String[] args) {
System.out.println("Global number is: " + globalNumber);
}
}

Operators - Arithmetic sum

public class ArithmeticSum {


public static void main(String[] args) {
int a = 15, b = 25, sum;
sum = a + b;
System.out.println("Sum = " + sum);
}
}

Operators - Swapping using Arithmetic operations

public class SwapUsingArithmetic {


public static void main(String[] args) {
int a = 10, b = 20;
a = a + b; // 30
b = a - b; // 10
a = a - b; // 20
System.out.println("After Swapping: a = " + a + ", b = " + b);
}
}

Operators - MCQs
Java Fundamentals: Programs and Concepts

Q1. What is the output of System.out.println(10 % 3)?


a) 1 b) 0 c) 3 d) 10
Answer: a) 1

Q2. Which operator is used to compare two values?


a) = b) == c) != d) &&
Answer: b) ==

Q3. What is the result of 5 + 2 * 3?


a) 21 b) 11 c) 15 d) 7
Answer: b) 11

You might also like