EvoNext
Відкрити в Telegram
Hi, I’m Biruk! Software Engineer bridging the gap between Full-Stack Development (Frontend & Backend), Server Environments, Computer Networks, and AI-driven Digital Art. Beyond Telegram, I love sharing my technical insights & build updates.
Показати більше1 619
Підписники
-224 години
-117 днів
-4430 днів
Архів дописів
1 619
Q2:Which of the following is true about Java’s enhanced for statement? Choose one.
1 619
Q1: Which of the following is the correct syntax for writing a methode with parameters?
1 619
LESSON 8: WRAPPER CLASSES IN JAVA
✅Wrapper classes provide a way to use primitive data types (int, boolean, etc..) as objects.
✳️Sometimes you must use wrapper classes, for example when working with Collection objects, such as ArrayList, where primitive types cannot be used (the list can only store objects):
example:
ArrayList<Integer> myNumbers = new ArrayList<Integer>(); // Valid
Creating Wrapper Objects
To create a wrapper object, use the wrapper class instead of the primitive type. To get the value, you can just print the object:
Example
public class Main {
public static void main(String[] args) {
Integer myInt = 5;
Double myDouble = 5.99;
Character myChar = 'A';
System.out.println(myInt);
System.out.println(myDouble);
System.out.println(myChar);
}
}
//
Share for programmer friends!>
https://t.me/PROGRAMINGLANGUAGES11 619
Q. What will be displayed when the following code is executed? int x = 0;
int number = 6;
while (number > 0) { number -= 3; System.out.print(number + " "); }
1 619
LESSON 7:
LOOPS AND NESTED LOOPS
✳️Looping in java helps by facilitating the execution of of a set of instructions repeatedly while some condition evaluates to true.
1. While-loops: allows the code to be executed repeatedly based on a given Boolean condition.
while (boolean condition)
{
loop statements...
}
2. for-loops: unlike while statement, it consumes the initialization, condition, and increment/decrement.
for (initialization condition; testing condition;
increment/decrement)
{
statement(s)
}
3. do-while: do while loop is similar to while loop with only difference that it checks for condition after executing the statements.
do
{
statements..
}
while (condition);
sample example for for-loop:
public class Loops
{
public static void main(String[] args)
{
ArrayList<Integer> ar = new ArrayList<>();//we will see about list in the next lessons
for (int i = 0; i < Integer.MAX_VALUE; i++)
{
ar.add(i);
}
}
}
link to get our Channel» https://t.me/PROGRAMINGLANGUAGES1»
group for your comments» https://t.me/learntocodecpp1 619
LESSON 7:
LOOPS AND NESTED LOOPS
✳️Looping in java helps by facilitating the execution of of a set of instructions repeatedly while some condition evaluates to true.
1. While-loops: allows the code to be executed repeatedly based on a given Boolean condition.
while (boolean condition)
{
loop statements...
}
2. for-loops: unlike while statement, it consumes the initialization, condition, and increment/decrement.
for (initialization condition; testing condition;
increment/decrement)
{
statement(s)
}
3. do-while: do while loop is similar to while loop with only difference that it checks for condition after executing the statements.
do
{
statements..
}
while (condition);
sample example for for-loop:
public class Loops
{
public static void main(String[] args)
{
ArrayList<Integer> ar = new ArrayList<>();//we will see about list in the next lessons
for (int i = 0; i < Integer.MAX_VALUE; i++)
{
ar.add(i);
}
}
}
link to get our Channel» https://t.me/PROGRAMINGLANGUAGES1»
group for your comments» https://t.me/learntocodecpp1 619
Q; Which code line could possibly "call" this method?
public static int SomeMethod(double[ ] array, int[ ] number)
{ . . . }
1 619
Q; What is the output of the following code fragment?
int [ ] odd = {1, 3, 5, 7, 9, 11 };
System.out.println( odd[0] + " " + odd[3] ) ;
1 619
LESSON 6: ARRAY AND 2D ARRAYS
✅An array is a collection of items stored at contiguous memory locations. The idea is to store multiple items of the same type together.
✳️Multidimensional Arrays can be defined in simple words as array of arrays. Data in multidimensional arrays are stored in tabular form (in row major order).
*In the array there will be:
data_type : type of data to be stored in the array
dimension: the dimension of the array is created. like 1D, 2D ...
array_name: name of the array
finally , the size of the array.
#example_of_array:;
class CODER
{
public static void main (String[] args)
{
// declares an Array of integers.
int[] arr;
// allocating memory for 5 integers.
arr = new int[5];
// initialize the first elements of the array
arr[0] = 10;
// initialize the second elements of the array
arr[1] = 20;
//so on...
arr[2] = 30;
arr[3] = 40;
arr[4] = 50;
// accessing the elements of the specified array
for (int i = 0; i < arr.length; i++)
System.out.println("Element at index " + i +
" : "+ arr[i]);
}
}
2D array:-
class Learn {
public static void main(String[] args)
{
int[][] arr = new int[10][20];
arr[0][0] = 1;
System.out.println("arr[0][0] = " + arr[0][0]);
}
}1 619
which method of Math Class of package java.util is not used for rounding a numbers to the nearest integer:
