Computer Science, asked by Dhruvsaraswat, 5 months ago

wap to print 16 30 44 ------------------n using loop java​

Answers

Answered by anindyaadhikari13
3

Required Answer:-

Question:

  • Write a program in Java to print 16 30 44...N using Loop.

Solution:

Here is the code.

  1. import java.util.*;
  2. public class JavaBrainly {
  3. public static void main(String[] args) {
  4. int n, a=16;
  5. Scanner sc=new Scanner(System.in);
  6. System.out.print("Enter range: ");
  7. n=sc.nextInt();
  8. for(int i=0;i<n;i++)
  9. {
  10. System.out.print(a+" ");
  11. a+=14;
  12. }
  13. sc.close();
  14. }
  15. }

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