1 777
订阅者
-124 小时
-177 天
-3330 天
帖子存档
1 777
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 777
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 777
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 777
Q; Which code line could possibly "call" this method?
public static int SomeMethod(double[ ] array, int[ ] number)
{ . . . }
1 777
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 777
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 777
which method of Math Class of package java.util is not used for rounding a numbers to the nearest integer:
1 777
LESSON 5:
JAVA MATH:
⚜️The Java Math class has many methods that allows you to perform mathematical tasks on numbers.
✳️The Math.sqrt(x) method returns the square root of x.
✳️The Math.max(x,y) method can be used to find the highest value of x and y.
✳️ The Math.abs(x) method returns the absolute (positive) value of x.
❤️ Math.random() returns a random number between 0.0 (inclusive), and 1.0 (exclusive).
public class Firsta {
public static void main(String[] args) {
double x,y,z;
/*double x = 3.14;
double y = 3.41;
double z = Math.max(x, y);
double a = Math.sqrt(5);
double ab = Math.ceil(x);// maximum number
double ac = Math.floor(y);// minimum number
System.out.println(z);*/
System.out.println(z);
System.out.println(z);
1 777
LESSON 5:
JAVA MATH
public class Firsta {
public static void main(String[] args) {
double x,y,z;
/*double x = 3.14;
double y = 3.41;
double z = Math.max(x, y);
double a = Math.sqrt(5);
double ab = Math.ceil(x);
double ac = Math.floor(y);
System.out.println(z);*/
1 777
WORKSHEET FOR JAVA |LEARN TO CODE
https://t.me/PROGRAMINGLANGUAGES1
SHARE FOR MORE PROGRAMMING MATERIALS : thanks
1 777
LESSON 4:
IMPORTING SCANNER CLASS IN | JAVA
👨🏽💻Scanner is a class in java.util package used for obtaining the input of the primitive types like int, double, etc. and strings.
✳️To read numerical values of a certain data type XYZ, the function to use is nextXYZ().
✅ To read strings, we use nextLine().
🔱To read a single character, we use next().charAt(0). next() function returns the next token/word in the input as a string and charAt(0) function returns the first character in that string.
import java.util.Scanner;
public class Firsta {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("enter some String");
String name = scanner.nextLine();
System.out.println("enter your age");
int x = scanner.nextInt();
scanner.nextLine();
System.out.println("what is you departent? ");
String dep =scanner.nextLine();
System.out.println("your name is: "+name);
System.out.println("your age is:"+ x);
System.out.println("your in "+dep+" departement now!");
}
}
» share and join this channel and
» GROUP To cONTRIBUTE YOUR SKILL1 777
#Q1, From the statements given below, select the choice which assigns a value to X ?
1 777
LESSON 3
ASSIGNMENT
✅> Every variables is assigned data type that designates the type and quantity of value it can hold.
✳️<> as many of you guess , variable is a name given to a memory location.
⚜️During declaration of a variable, we nedd to take care of two things
1. Dataype
2. Dataname
Similarly , we can initialize variables by assigning values in two ways:
1.variable initialization//
2. Assigning value by taking input from user//
/look the snippet code below with different dataypes and initializations
public class Firsta {
public static void main(String[] args) {
long x = 2345267;
float y =3.45f;
boolean z = true;
char ch = '@';
String str ="learn to code!!";
System.out.println("the number is: " +x);
System.out.println(y);
System.out.println(z);
System.out.println(ch);
System.out.println(str);
现已上线!2025 年 Telegram 研究 — 年度关键洞察 
