At Westonci.ca, we provide reliable answers to your questions from a community of experts. Start exploring today! Connect with a community of experts ready to provide precise solutions to your questions on our user-friendly Q&A platform. Experience the ease of finding precise answers to your questions from a knowledgeable community of experts.

write a java program to print the following series:
1 5 9 13 17...n terms​


Sagot :

Answer:

In Java:

import java.util.*;

public class Main{

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

int n;

System.out.print("Max of series: ");

n = input.nextInt();

for(int i = 1; i<=n;i+=4){

    System.out.print(i+" ");

}

}

}

Explanation:

This declares n as integer. n represents the maximum of the series

int n;

This prompts the user for maximum of the series

System.out.print("Max of series: ");

This gets user input for n

n = input.nextInt();

The following iteration prints from 1 to n, with an increment of 4

for(int i = 1; i<=n;i+=4){

    System.out.print(i+" ");

}