13. Write a Java program to print the following series :
(i) 258 11 ................., N (using while loop)
(ii) 15 9 13 ................N (using do while loop)
Answers
Answered by
0
Answer:
15 9 13.............. do while loop
Answered by
1
Question 1:-
Write a Java program to print the following series.
2 5 8 11 .....N terms.
Program:-
Here is your program written in Java.
import java.util.*;
class Series
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter N: ");
int n=sc.nextInt();
int i=1, a=2;
while(i++<=n)
{
System.out.print(a+" ");
a+=3;
}
}
}
Question 2:-
Write a program to print the following series.
1 5 9 13....N terms.
Program:-
Here is your program.
import java.util.*;
class Series
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.print("Enter N: ");
int n=sc.nextInt();
int i=1, a=1;
do
{
System.out.print(a+" ");
a+=4;
} while(i++<=n);
}
}
Similar questions