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+" ");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+" ");
}
Explanation: