Home Answers Viewqa Java-Interview-Questions WAP in java to print the series 1*2*3

 
 


Deepak singh
WAP in java to print the series 1*2*3
3 Answer(s)      a year and 10 months ago
Posted in : Java Interview Questions

WAP in java to print the series 123

View Answers

July 12, 2011 at 10:51 AM


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

July 12, 2011 at 8:43 PM


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

July 13, 2011 at 9:55 AM


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









Related Pages:
wap

Ask Questions?

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.