
WAP in java to print the series 123

import java.util.*;
class Series
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
System.out.print("Enter value of n: ");
int num=input.nextInt();
for(int i=1;i<=num;i++){
System.out.print(i+" ");
}
}
}

import java.util.Scanner;
public class Series {
public static void main(String args[])
{
int mul=1;
Scanner input=new Scanner(System.in);
System.out.print("Enter value of n: ");
int num=input.nextInt();
for(int i=1;i<=num;i++){
mul=mul*i;
System.out.println(i+"*="+mul);
}
}
}
output:
Enter value of n: 5
1*=1
2*=2
3*=6
4*=24
5*=120
BUILD SUCCESSFUL (total time: 5 seconds)
//Executed successfully

import java.util.Scanner;
/**
*
* @author Umra
*/
public class Series {
public static void main(String args[])
{
int mul;
Scanner input=new Scanner(System.in);
System.out.print("Enter value of n: ");
int num=input.nextInt();
for(int i=1;i<=num;i++)
{
System.out.println("\n");
mul=1;
for(int j=i;j>=1;j--)
{
mul=mul*j;
System.out.print(j+" * ");
}
System.out.print("1 ="+mul);
}
}
}
output:
Enter value of n: 5
1 * 1 =1
2 * 1 * 1 =2
3 * 2 * 1 * 1 =6
4 * 3 * 2 * 1 * 1 =24
5 * 4 * 3 * 2 * 1 * 1 =120
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.