java programm

download java programm

of 43

Transcript of java programm

  • 7/29/2019 java programm

    1/43

    1 | P a g e

    PROGRAM 1

    AIM: To add two numbers (dynamic program)

    var a,b,ad;

    a=parseInt(prompt("please enter Ist number to be added"));

    b=parseInt(prompt("please enter 2nd number to be added"));

    ad=a+b;

    document.write("when we add "+a);

    document.write(" to "+b);

    document.write(" ,the result is "+ad);

  • 7/29/2019 java programm

    2/43

    2 | P a g e

  • 7/29/2019 java programm

    3/43

    3 | P a g e

  • 7/29/2019 java programm

    4/43

    4 | P a g e

    PROGRAM 2

    AIM: To subtract two numbers (dynamic program)

    var a,b,s;

    a=parseInt(prompt("please enter the number to be subtracted"));

    b=parseInt(prompt("please enter the number from which you want the first number to besubtracted"));

    s=b-a;

    document.write("when we subtract "+a);

    document.write(" from "+b);

    document.write(" ,the result is "+s);

  • 7/29/2019 java programm

    5/43

    5 | P a g e

  • 7/29/2019 java programm

    6/43

    6 | P a g e

  • 7/29/2019 java programm

    7/43

    7 | P a g e

    PROGRAM 3

    AIM: To multiply two numbers (dynamic program)

    var a,b,m;

    a=parseInt(prompt("please enter Ist number"));

    b=parseInt(prompt("please enter 2nd number"));

    m=a*b;

    document.write("when we multiply "+a);

    document.write(" by "+b);

    document.write(" ,the result is "+m);

  • 7/29/2019 java programm

    8/43

    8 | P a g e

  • 7/29/2019 java programm

    9/43

    9 | P a g e

  • 7/29/2019 java programm

    10/43

    10 | P a g e

    PROGRAM 4

    AIM: To divide two numbers (dynamic program)

    var a,b,d;

    a=parseInt(prompt("please enter the number to be divided"));

    b=parseInt(prompt("please enter the number by which you want to divide the first number"));

    d=a/b;

    document.write("when we divide "+a);

    document.write(" by "+b);

    document.write(" ,
    the result is "+d);

  • 7/29/2019 java programm

    11/43

    11 | P a g e

  • 7/29/2019 java programm

    12/43

    12 | P a g e

  • 7/29/2019 java programm

    13/43

    13 | P a g e

    PROGRAM 5

    AIM: To find the greatest of three numbers

    var a,b,c,g;

    a=parseInt(prompt("please enter Ist number"));

    b=parseInt(prompt("please enter 2nd number"));

    c=parseInt(prompt("please enter 3rd number"));

    if(a>=b)

    g=a;

    else

    g=b;

    if(g>=c)

    {document.write("Out of " +a);

    document.write(" , " +b);

    document.write(" and " +c);

    document.write(" ; the greatest number is " +g);}

    else

    {document.write("Out of " +a);

    document.write(" , " +b);

    document.write(" and " +c);

    document.write(" ; the greatest number is " +c);}

  • 7/29/2019 java programm

    14/43

    14 | P a g e

  • 7/29/2019 java programm

    15/43

    15 | P a g e

  • 7/29/2019 java programm

    16/43

    16 | P a g e

    PROGRAM 6

    AIM: To find the greatest of three numbers(using nested if-else)

    var a,b,c,g;

    a=parseInt(prompt("please enter Ist number"));

    b=parseInt(prompt("please enter 2nd number"));

    c=parseInt(prompt("please enter 3rd number"));

    if(a>=b)

    {if(a>=c)

    document.write("greatest of the three numbers is " +a)}

    else

    {

    if(b>=c)

    document.write("greatest of the three numbers is " +b)

    else

    document.write("greatest of the three numbers is " +c)

    }

  • 7/29/2019 java programm

    17/43

    17 | P a g e

  • 7/29/2019 java programm

    18/43

    18 | P a g e

  • 7/29/2019 java programm

    19/43

    19 | P a g e

    PROGRAM 7

    AIM: To grade students using If-else statement, conditional && operator

    Javascript

    var num1,num2,num3;

    num1=parseInt(prompt("Please enter the marks of ASM ",""));

    num2=parseInt(prompt("Please enter the marks of FSM ",""));

    num3=parseInt(prompt("Please enter the marks of MR ",""));

    total = num1+num2+num3;

    per = total/300*100;

    if(per >=70)

    document.write("Grade of the Student is A+");

    else if( (per>=60) && (per=50) && (per=40) && (per

  • 7/29/2019 java programm

    20/43

    20 | P a g e

  • 7/29/2019 java programm

    21/43

    21 | P a g e

  • 7/29/2019 java programm

    22/43

    22 | P a g e

    PROGRAM 8

    AIM: To swap two numbers using third number

    Javascript

    var num1,num2,temp;

    num1=parseInt(prompt("Enter any integer number ",""));

    num2=parseInt(prompt("Enter any integer number ",""));

    document.write("Value of first number before swap is "+num1);

    document.write("
    Value of second number before swap is "+num2);

    temp=num1;

    num1=num2;

    num2=temp;

    document.write("
    Value of first number after swap is "+num1);

    document.write("
    Value of second number after swap is "+num2);

  • 7/29/2019 java programm

    23/43

    23 | P a g e

  • 7/29/2019 java programm

    24/43

    24 | P a g e

  • 7/29/2019 java programm

    25/43

    25 | P a g e

    PROGRAM 9

    AIM: To swap two numbers without using third number

    Javascript

    var a,b;

    a=parseInt(prompt("Enter any integer number ",""));

    b=parseInt(prompt("Enter any integer number ",""));

    document.write("Value of first number before swap is "+a);

    document.write("
    Value of second number before swap is "+b);

    a=a+b;

    b=a-b;

    a=a-b;

    document.write("
    Value of first number after swap is "+a);

    document.write("
    Value of second number after swap is "+b);

  • 7/29/2019 java programm

    26/43

    26 | P a g e

  • 7/29/2019 java programm

    27/43

    27 | P a g e

  • 7/29/2019 java programm

    28/43

    28 | P a g e

    PROGRAM 10

    AIM: To choose out of the various arithmetic operations

    Javascript

    1 Press A/a for addition

    2 Press M/m for multiplication

    3 Press S/s for subtraction

    4 Press D/d for division

  • 7/29/2019 java programm

    29/43

    29 | P a g e

    document.write(" ,the result is "+c);

    }

    else if( (ch=='S') || (ch=='s') )

    {

    c=a-b;

    document.write("when we subtract "+a);

    document.write(" from "+b);

    document.write(" ,the result is "+c);

    }

    else if( (ch=='D') || (ch=='d') )

    {

    c=a/b;

    document.write("when we divide "+a);

    document.write(" by "+b);

    document.write(" ,
    the result is "+d);

    }

    else

    {

    document.write("WRONG KEY PRESSED");

    }

  • 7/29/2019 java programm

    30/43

    30 | P a g e

  • 7/29/2019 java programm

    31/43

    31 | P a g e

  • 7/29/2019 java programm

    32/43

    32 | P a g e

    PROGRAM 11

    AIM: To find out the number of even numbers between the two numbers & their sum using

    While Loop

    Javascript

    var a,i,n,count=0,sum=0;

    i=parseInt(prompt("Please Enter the start value "));

    n=parseInt(prompt("Please Enter the last value "));

    a=i;

    while(i

  • 7/29/2019 java programm

    33/43

    33 | P a g e

  • 7/29/2019 java programm

    34/43

    34 | P a g e

  • 7/29/2019 java programm

    35/43

    35 | P a g e

    PROGRAM 12

    AIM: To find out the numbers divisible by 3 & 5 between the two numbers by using For Loop

    Javascript

    var a,i,n,count=0;

    i=parseInt(prompt("Please enter the ist number"));

    n=parseInt(prompt("Please enter the last number"));

    a=i;

    document.write("Between "+i);

    document.write(" and "+n);

    document.write(", Following numbers are divisible by 3 & 5:
    ");

    for(i=1;i

  • 7/29/2019 java programm

    36/43

    36 | P a g e

  • 7/29/2019 java programm

    37/43

    37 | P a g e

  • 7/29/2019 java programm

    38/43

    38 | P a g e

    PROGRAM 13

    AIM: To find the greatest of three numbersusing function

    Javascript Function

    function big(a,b,c)

    {

    if(a>=b)

    g=a;

    else

    g=b;

    if(g>=c)

    alert("The greatest number is " +g);

    else

    alert("The greatest number is " +c);

    }

    var a,b,c,g;

    a=parseInt(prompt("Enter the first number",""));

    b=parseInt(prompt("Enter the 2nd number",""));

    c=parseInt(prompt("Enter the 3rd number",""));

    big(a,b,c);

  • 7/29/2019 java programm

    39/43

    39 | P a g e

  • 7/29/2019 java programm

    40/43

    40 | P a g e

  • 7/29/2019 java programm

    41/43

    41 | P a g e

    PROGRAM 14

    AIM: To find the percentage of marks obtainedusing function with return

    Javascript Function

    function per(a,b,c)

    {var total,p;

    total=a+b+c;

    p=total/3;

    return(p)

    }

    var a,b,c,result;

    a=parseInt(prompt("Please enter the marks of ASM "));

    b=parseInt(prompt("Please enter the marks of FSM "));

    c=parseInt(prompt("Please enter the marks of MR "));

    result=per(a,b,c);

    document.write("You have obtained "+result);

    document.write("% marks ");

  • 7/29/2019 java programm

    42/43

    42 | P a g e

  • 7/29/2019 java programm

    43/43