Вы находитесь на странице: 1из 2

** If I see for (int x = 1; x <=5; x++), I read it in the following format in my head: for an integer x

starting at 1, as long as x is less than or equal to 5, increment x.


** for loop and while loop are called entry controlled whereas do while is called exit controlled.
-Entry controlled first check the condition then execute the statement
-Exit controlled first execute the statement then check the condition
(it means what compiler does first... in for loop it checks the condition first then proceeds
with the rest of the code. same for while... but do is another loop that at least compiles a statement
even for once... and after the compilation it proceeds with the condition followed by "while" loop... it
keeps compiling until condition becomes false... but if the condition is false at the very first time, it
doesn't compile anymore)
- A do while loop tests the condition before running the code (which is false - the condition is tested
after the code ran once. The While loop tests the condition first).
- A do while loop runs your code at least one time (which is true, the condition is evaluated after the
code ran once.)
- A while loop runs the code before testing the condition (Which is false - the do..while loop does
that.)
Arrays: -
Think of arrays as boxes that you put you data but instead of starting to count from 1 with arrays the
index starts from 0. So you have five boxes from 0-4. Like this.
Array index 0 1 2 3 4
Int value 98768
Array code flip: -
can you write a code that will flip your array from {6, 42, 3, 7} to {7, 3, 42, 6}. Please some help me
understand array flipping.
public class Program {
public static void main (String[] args) {
int [] myArr = {6, 42, 3, 7};
int [] reverseMyArr = new int[myArr.length];

int z = 0;
for(int x = myArr.length – 1; x >= 0; x--){
reverseMyArr[z] = myArr[x];
z++;
}
for (int i:reverseMyArr) {
System.out.println(i);
}
}
}
Classes and objects:-
*Class*- Noun or pronoun/ Person, Place, Thing (girl,car,dog /she,he...)
*Attributes*- Adjective/Which one? What kind?/{size, dimension, magnitude, direction, ...}
(beautiful,small,fast...) Should be objectively measurable.
*Behaviour*- Verb/Action or description of state of being / (run,Dance,Jump, )

*void just means the function doesn't return any value.


If I had to describe void it would be like me giving an apple to a person1 and telling them, "give
this to that person2 over there and come back. " the person1 gives the apple and returns empty
handed, he returns with nothing of value. so the person2 receives the apple and we dont take
anything in return

*Static is mostly used if you want to know something without an object being created or to know
something that is always the same for all objects of a class. For example you may want to know
if Apples are fruits or a vegetables. Because all apples are fruits you don't need to make an
objectapple and check if it is a fruit. You can write a Static checkFruit() method that tells you
"all apples are fruits". This method doesn't change and it's not different for objectapple1 to
objectapple2. You can call this method without even creating a single object.

Вам также может понравиться