Write a java program to give the following output:
1)
46656
7776
1296
216
36
6
1
Answers
Answered by
2
Required Answer:-
Question:
Write a Java program for the following output.
46656
7776
1296
216
36
6
1
Solution:
Here comes the program.
public class Pattern {
public static void main(String[] args) {
for(int i=1,a=46656;i<=7;i++,a/=6)
System.out.println(a);
}
}
Explanation:
Each row of the pattern is a number which is in the form of 6ⁿ where n={7,6,5,..1}
Here,
46656 = 6⁶
7776 = 6⁵
1296 = 6⁴
216 = 6³
36 = 6²
6 = 6¹
1 = 6⁰
So, we have created an integer (a) whose initial value is 46656.
After each iteration, the value of a is displayed on the screen and then, a is divided by 6 to obtain the next term for the pattern.
Output:
46656
7796
1296
216
36
6
1
Attachments:
Similar questions
Political Science,
1 month ago
English,
1 month ago
English,
3 months ago
Social Sciences,
3 months ago
Math,
10 months ago
History,
10 months ago