wap to print 16 30 44 ------------------n using loop java
Answers
Answered by
3
Required Answer:-
Question:
- Write a program in Java to print 16 30 44...N using Loop.
Solution:
Here is the code.
- import java.util.*;
- public class JavaBrainly {
- public static void main(String[] args) {
- int n, a=16;
- Scanner sc=new Scanner(System.in);
- System.out.print("Enter range: ");
- n=sc.nextInt();
- for(int i=0;i<n;i++)
- {
- System.out.print(a+" ");
- a+=14;
- }
- sc.close();
- }
- }
Explanation:
- Logic is very simple. Difference between each term is 16. In this program, we will create a loop that iterates n times and we will print the value of a. Initially, value of a is 16. After each iteration, 14 is added to a.
Output is attached for verification.
Attachments:
Similar questions