Answer:
Explanation:
The following code is written in Java and it uses nested for loops to create the array elements and then the same for loops in order to print out the elements in a pyramid-like format as shown in the question. The output of the code can be seen in the attached image below.
class Brainly {
public static void main(String[] args) {
int jagged[][] = new int[5][];
int element = 1;
for(int i=0; i<5; i++){
jagged[i] = new int[i+1]; // creating number of columns based on current value
for(int x = 0; x < jagged[i].length; x++) {
jagged[i][x] = element;
element += 1;
}
}
System.out.println("Jagged Array elements are: ");
for ( int[] x : jagged) {
for (int y : x) {
System.out.print(y + " ");
}
System.out.println(' ');
}
}
}
The code segment illustrates the use of conditional statements.
The execution of conditional statements is dependent on the truth value of its condition.
The required code segment is as follows:
<em>if (rsvp == true && selection = 1){</em>
<em> option1 = "Thanks for attending. You will be served beef.";</em>
<em>}</em>
<em>else{</em>
<em>option1 = "Sorry you can't make it.";</em>
<em>}</em>
<em />
The flow of the above code segment is as follows:
- Check if rsvp is true and selection is 1; if yes, "Thanks for attending....." is saved in option1
- If otherwise, "Sorry...." is saved in option1
The code segment submitted can be used for several programming languages such as <em>Java, C++, C and C#.</em>
Read more about similar programs at:
brainly.com/question/14166674
The correct answer is Home :)
Answer:
- #include <iostream>
- using namespace std;
- int hailstoneLength(int n){
- int term = 1;
- while(n != 1){
- if(n % 2 == 0){
- n = n / 2;
- term++;
- }
- else{
- n = n * 3 + 1;
- term++;
- }
- }
- return term;
- }
- int main()
- {
- cout<<hailstoneLength(8);
- return 0;
- }
Explanation:
Hailstone sequence is a list of number that is generated by following the rules as below:
- Given a starting number (e.g. 5)
- If the number is even, divide it by 2
- If the number is odd, multiply it by 3 and then add 1
- the starting number will either be repeatedly divided or multiplied until the final n reaches 1
So, we can create a function called hailstoneLength that takes one input number, n, as starting number (Line 4).
In the function initialize the variable term with value of 1 (Line 5). Create a while loop and set the condition to enable the loop running until the n become 1 (Line 6). In the loop, keep checking the n value if it is currently even or odd using modulus operator (Line 7 - 14). If it is even, divide n by 2 and increment the term by one (Line 7 - 10). If it is odd, multiple it by 3 and add 1 (Line 11 - 14). At last, return term value as output (Line 16).
In the main program, test the function by passing 8 as argument. We shall get the output of 4 (Line 21).
Answer:
All of the above. Explanation:Credible sites include the date of any information, cite the source of the information presented, are well designed and professional.