Data types, variables, and operators
Understanding data types helps you store different kinds of information in your programs. Variables are containers for storing data, while operators perform actions on data.
Examples
public class Examples { public static void main(String[] args) { // Example 1: Using variables to store numbers int x = 10; int y = 20; int sum = x + y; System.out.println("Sum of x and y: " + sum); // Example 2: Combining strings using concatenation String firstName = "John"; String lastName = "Doe"; String fullName = firstName + " " + lastName; System.out.println("Full Name: " + fullName); // Example 3: Using comparison operators to compare values int a = 5; int b = 10; boolean result = (a > b); // false System.out.println("Is a greater than b? " + result); } }
FAQ (interview questions and answers)
-
What is a variable in Java?
A reserved word in Java
A container for storing data
A type of loop in Java
-
What are data types?
Types of values that can be stored in variables
Variables that store only numeric values
Data stored in files
-
What do operators do in Java?
Perform actions on data
Store data in variables
Create new variables
-
What is the purpose of using variables?
To print output to the console
To execute Java code
To store and manipulate data
-
How can you combine strings in Java?
Using comparison operators
Using concatenation
Using arithmetic operators
Your Total Score: 0 out of 5
Remember to just comment if you have any doubts or queries.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.