[SUPER CHALLENGE]
Make your own Java Códe to get the following 'W' pattern as output.
, ,,,,,,,, ,
,, ,,, ,,, ,,
,,, ,, ,, ,,,
,,,,, ,,,,,
Hint:- The above pattern contains 6 triangle pattern and 1 pyramid pattern.
_
• CORRECT PATTERN IS GIVEN IN ATTACHMENT. If it is not properly given in the question Check The ATTACHMENT.
• Do not be greedy of points.
• Do not spam or post copied answers.
• Try your best! Good Luck!
Answers
More questions related to String Manipulation -
- https://brainly.in/question/37937856
- https://brainly.in/question/35135863
- https://brainly.in/question/33815868
- https://brainly.in/question/13379846
- https://brainly.in/question/21529758
Solution:
Here comes my approach.
public class Pattern {
public static void main(String args[]){
int i;
for(i=1;i<=4;i++){
dots(1,i);
spaces(i,3);
dots(i,4);
spaces(3,2*i);
dots(i,4);
spaces(i,3);
dots(1,i);
System.out.println();
}
}
static void dots(int i,int j){
for(int k=i;k<=j;k++)
System.out.print(".");
}
static void spaces(int i,int j){
for(int k=i;k<=j;k++)
System.out.print(" ");
}
}
There are two functions - dots(i,j) and spaces(i,j).
- dots(): This function creates dots in the pattern.
- spaces(): This function creates spaces between the dots where necessary.
Both functions are called inside the loops. Hence the pattern is printed.
See the attachment for output.
•••♪