Question: JAVA PROGRAMMING ONLY** please following the output answer (Template for Task) for both task 1 and 2 the answer have to be the same Task1:
JAVA PROGRAMMING ONLY** please following the output answer (Template for Task) for both task 1 and 2
the answer have to be the same
Task1:
Suppose
m
is the even number right after your last-two digits of the PantherID. //number 62
program that sums 30 even numbers after
m
(including
m
) [Using For-loop]. Call
this method and print out the sum from the For-loop.
The above arithmetic sequence will be: m, m+2, m+4, ... m+(n-1)*2, where n is 30. The
sum of this sequence can be represented as S=n/2*(2m+(n-1)*2), where n is30. Use the
equation to calculate and print out the sum of this sequence.
Expected Output of Task 1:
Template for Task1:
//=======================================
public
class
Lab_01{
//Method for calculating the sum of Arithmetic Sequence
Public static int Arithmetic_sequence( int n, int number){
}
Public static void main(String[] args
){
//Last-two digits of the Panther ID
Int n = 26;
//Initialize a temporary value to save the sum
Int sum =;
//For-loop to calculate the sum
for(){
}
//Print the result of the for-loop
System.out.println("The result of for-loop is: " + sum);
//Print the result of the method
System.out.println("The result of the method is: " + Arithmetic_sequence(n, 30));
}
}
Task2
:
Suppose n is the last digit of you PantherID;
n=n+5.
Draw a Square whose side length is n
with two methods. The first method is called FLside (
n
) with an integer parameter that indicates the number of "x" to draw this side.
The second method is called Mside(
n
) with an integer parameter; in this method, only
the first and last position will draw "x", the other positions are fulfilled by "a". The
example below shows the example of a square whose length is 26.
Calculate the area of the square by writing a method called Area(
n
) with an integer
parameter.
Expected Output of Task 2:
Template for Task2:
//=======================================
//The method to draw the first and last side
Public static void LFside(int n){
}
//The method to draw the intermediate side
Public static void Mside( int n){
}
//The method to calculate the area of the square
Public static void Area( int n){
}
Public static void main(String[] args){
//Initialize the value of n
Int n = 26 + 5;
//Draw first side
LFside (n);
//Draw intermediate sides
For (){
Mside(n);
}
//Draw last side
LFside(n);
//Calculate and print the area of the square
Area(n):
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
