⬜◻◽ HeÿA frndz ◽◻⬜
Generate the following series in Java
11,22,33,44.........n terms
#Compuer Science
Thanks ☺
Answers
CODE :
import java.util.*;
class series
{
public static void main(String args[])
{
Scanner sc=new Scanner(System,.in);
System.out.println("Enter a limit");
int n=sc.nextInt();
int a=11;
for(int i=1;i<=n;i++)
{
System.out.println(a+" , ");
a=a+11;
}
}
}
-------------------------------------------------------------------
OUTPUT :
Enter a limit
4
11,22,33,44
--------------------------------------------------
CONCEPT :
⇒ First we should be knowing the fact that whenever we have to print anything upto n terms then start a loop from 1 and continue till n.
⇒ Then do whatever operations taking another variable into consideration.
⇒ Here I have taken a as the variable.
⇒ The series should begin with a and hence I have assigned a to be 11
⇒ Then within the loop I have added 11 with a everytime.
⇒ This helps to print the given series.
Hope it helps !
_________________________________________________________________________