Answer:
Explanation:
The following code is written in Java. It creates the Bug class with the position and direction variables. Then it creates a constructor, move method, turn method, and getPosition method. Finally, a bug object called bugsy is created in the main method, and we move it once to the right, then again to the right, and then we turn it and move it 5 times to the left, printing out the position when it is done moving. Output can be seen in the attached picture below.
class Brainly {
public static void main(String[] args) {
Bug bugsy = new Bug(10);
bugsy.move();
System.out.println("Current bug position: " + bugsy.getPosition());
bugsy.move();
System.out.println("Current bug position: " + bugsy.getPosition());
bugsy.turn();
bugsy.move();
bugsy.move();
bugsy.move();
bugsy.move();
bugsy.move();
System.out.println("Current bug position: " + bugsy.getPosition());
}
}
class Bug {
char direction = 'r';
int position = 0;
public Bug(int initialPosition) {
this.position = initialPosition;
}
public void turn() {
if (this.direction == 'r') {
this.direction = 'l';
} else {
this.direction = 'r';
}
}
public void move() {
if (this.direction == 'r') {
this.position += 1;
} else {
this.position -= 1;
}
}
public int getPosition() {
return this.position;
}
}
The answer would be D. New Slide
Answer:
A. Source code
Explanation:
In the field of Programming; Source code is the code written in high level language given to the computer to translate to machine - executable code before executing. It is usually written and understood by human. It is closer to human like language, as it allows easier expression. It is mostly consist of english-like statement.
So, Erik would primarily be writing source code when performing his daily tasks since his daily task require high level of computer programming and internet knowledge.
Answer:
In Python:
def is_power(n):
if n > 2:
n = n/2
return is_power(n)
elif n == 2:
return True
else:
return False
Explanation:
This defines the function
def is_power(n):
If n is greater than 0
if n > 2:
Divide n by 2
n = n/2
Call the function
return is_power(n)
If n equals 2
elif n == 2:
Return True
return True
If n is less than 2
else:
Then, return false
return False
Answer:
30cm
Explanation:
Height X Base
6cm X 10cm
60cm
Then take half because a triangle is half a square and we are using a square formula.
60cm divided by 2
=30cm