WAP in java to print the series 1*2*3

Ads
 

WAP in java to print the series 1*2*3

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

Ads









Related Tutorials/Questions & Answers:
WAP in java to print the series 1*2*3
java programming:generating series
Advertisements
loop code to print the Pyramid: 1 1234 12 123 123 12 1234 1
Maven dependency for com.liferay - com.liferay.gradle.plugins version 13.0.23 is released. Learn to use com.liferay.gradle.plugins version 13.0.23 in Maven based Java projects
Maven dependency for org.wso2.identity.apps - org.wso2.identity.apps.console.server.feature version 1.2.223 is released. Learn to use org.wso2.identity.apps.console.server.feature version 1.2.223 in Maven based Java projects
Maven dependency for com.liferay - com.liferay.gradle.plugins version 13.1.23 is released. Learn to use com.liferay.gradle.plugins version 13.1.23 in Maven based Java projects
Maven dependency for org.kohsuke.stapler - stapler version 1.263 is released. Learn to use stapler version 1.263 in Maven based Java projects
Maven dependency for org.wso2.identity.apps - org.wso2.identity.apps.recovery.portal.server.feature version 1.2.323 is released. Learn to use org.wso2.identity.apps.recovery.portal.server.feature version 1.2.323 in Maven based Java projects
Maven dependency for org.wso2.identity.apps - org.wso2.identity.apps.common.server.feature version 1.2.283 is released. Learn to use org.wso2.identity.apps.common.server.feature version 1.2.283 in Maven based Java projects
Maven dependency for org.wso2.identity.apps - org.wso2.identity.apps.authentication.portal.server.feature version 1.2.113 is released. Learn to use org.wso2.identity.apps.authentication.portal.server.feature version 1.2.113 in Maven based Java projects
Maven dependency for org.wso2.identity.apps - org.wso2.identity.apps.recovery.portal.server.feature version 1.2.253 is released. Learn to use org.wso2.identity.apps.recovery.portal.server.feature version 1.2.253 in Maven based Java projects
Maven dependency for com.trib3 - json version 1.10.1233 is released. Learn to use json version 1.10.1233 in Maven based Java projects
Maven dependency for org.wso2.identity.apps - org.wso2.identity.apps.recovery.portal.server.feature version 1.2.233 is released. Learn to use org.wso2.identity.apps.recovery.portal.server.feature version 1.2.233 in Maven based Java projects
Maven dependency for org.wso2.identity.apps - org.wso2.identity.apps.myaccount.server.feature version 1.2.363 is released. Learn to use org.wso2.identity.apps.myaccount.server.feature version 1.2.363 in Maven based Java projects
Maven dependency for com.lasmanis - javapatterns version 1.2.93 is released. Learn to use javapatterns version 1.2.93 in Maven based Java projects
Maven dependency for com.cognitect.aws - endpoints version 1.1.12.13 is released. Learn to use endpoints version 1.1.12.13 in Maven based Java projects
Maven dependency for org.noear - solon.view.beetl version 1.0.3.23 is released. Learn to use solon.view.beetl version 1.0.3.23 in Maven based Java projects
SERIES PROGRAMMING
Maven dependency for com.liferay - com.liferay.gradle.plugins version 13.2.3 is released. Learn to use com.liferay.gradle.plugins version 13.2.3 in Maven based Java projects
Maven dependency for com.liferay - com.liferay.source.formatter version 1.0.1123 is released. Learn to use com.liferay.source.formatter version 1.0.1123 in Maven based Java projects
Maven dependency for com.liferay - com.liferay.source.formatter version 1.0.1023 is released. Learn to use com.liferay.source.formatter version 1.0.1023 in Maven based Java projects
Maven dependency for com.liferay - com.liferay.jenkins.results.parser version 1.0.823 is released. Learn to use com.liferay.jenkins.results.parser version 1.0.823 in Maven based Java projects
Maven dependency for org.wso2.identity.apps - org.wso2.identity.apps.recovery.portal.server.feature version 1.2.123 is released. Learn to use org.wso2.identity.apps.recovery.portal.server.feature version 1.2.123 in Maven based Java projects
Maven dependency for org.wso2.identity.apps - org.wso2.identity.apps.console.server.feature version 1.2.133 is released. Learn to use org.wso2.identity.apps.console.server.feature version 1.2.133 in Maven based Java projects
Maven dependency for com.liferay - com.liferay.portal.settings.web version 1.2.33 is released. Learn to use com.liferay.portal.settings.web version 1.2.33 in Maven based Java projects
Maven dependency for com.alibaba - fastjson version 1.2.73 is released. Learn to use fastjson version 1.2.73 in Maven based Java projects
Maven dependency for com.joseflavio - iperoxo version 1.0-A23 is released. Learn to use iperoxo version 1.0-A23 in Maven based Java projects
Maven dependency for org.clojure - clojure version 1.10.2-rc3 is released. Learn to use clojure version 1.10.2-rc3 in Maven based Java projects
Maven dependency for com.frostwire - jlibtorrent version 1.2.0.16-RC3 is released. Learn to use jlibtorrent version 1.2.0.16-RC3 in Maven based Java projects
Maven dependency for com.bullhorn - sdk-rest version 1.4.23 is released. Learn to use sdk-rest version 1.4.23 in Maven based Java projects
Maven dependency for org.wildfly.security - wildfly-elytron version 1.2.0.Beta3 is released. Learn to use wildfly-elytron version 1.2.0.Beta3 in Maven based Java projects

Ads