Search This Blog

Sunday 3 August 2014

01. HTML and JSP Program to Find Biggest Number among 2, 3 and N Numbers.

//File name: Big.html
<HTML>
    <HEAD>
        <TITLE>Biggest Number</TITLE>
    </HEAD>

    <BODY>
        <H1>Program to find biggest of 2, 3 or N numbers using method overloading</H1>
        <FORM name="frm" ACTION="Big.jsp" METHOD="POST" >
            <h3> Enter 2, 3 or N numbers (Press Enter key after one input):<h3>
                    
        <TEXTAREA NAME="textarea1" autofocus onfocus="textarea1.value=''" ROWS="1"> 


        </TEXTAREA>
            <BR>
            <INPUT TYPE="SUBMIT"   VALUE="Submit" >
        </FORM>
    </BODY>
<HTML>


//Filename: Big.jsp
//01.Program to find biggest number from 2,3 or N numbers using method overloading.
<HTML>
    <HEAD>
        <TITLE>Program to find biggest number among given numbers</TITLE>
       <%@ page import="java.io.*,java.util.*,java.lang.*" %>
    </HEAD>

    <BODY>
   
    <%
        String str=request.getParameter("textarea1");
        char ch[]=str.toCharArray();
        int len= str.length();
        int dig=0,op1,op2,op3,op4;
    %>
    <%!
        int big;
        int a[]=new int[100];
        int j=0,i;
    %>
    <%
        for(i=0;i<len;i++)
        {
       
            if(ch[i]=='\r')
            {
                switch(i)
                {
                   
                case 1:
                    a[j++]=Character.getNumericValue(ch[i-1]);
                    len=0;
                    break;
               
                case 2:
               
                    op1=Character.getNumericValue(ch[i-2]);
                    op2=Character.getNumericValue(ch[i-1]);
                    dig=op1*10+op2;
                    a[j++]=dig;
                    len=0;
                    break;
               
                case 3:
               
                    op1=Character.getNumericValue(ch[i-3]);
                    op2=Character.getNumericValue(ch[i-2]);
                    op3=Character.getNumericValue(ch[i-1]);
                    dig=op1*100+op2*10+op3;
                    a[j++]=dig;
                    len=0;
                    break;
                case 4:
                    op1=Character.getNumericValue(ch[i-4]);
                    op2=Character.getNumericValue(ch[i-3]);
                    op3=Character.getNumericValue(ch[i-2]);
                    op4=Character.getNumericValue(ch[i-1]);
                    dig=op1*1000+op2*100+op3*10+op4;
                    a[j++]=dig;
                    len=0;
                    break;
                default:
                    out.println("Default");
                }
           
            }
        }
        %>
       
        <h3 color=blue>    The given numbers are:</h3>
        <br>
        <%
        for(i=0;i<j;i++)
        {
            out.println("a["+i+"]="+a[i]);
            %>
            <BR>
            <%
        }
    %>

   
    <BR>
    <%
        out.println("Biggest Number is:");
        if(j==2)
             big=biggest(a[0],a[1]);
        else if(j==3)
            big =biggest(a[0],a[1],a[2]);
        else
            big=biggest(a,j);

        out.println(big);
    %>
   
    <%!
        int biggest(int a, int  b) // for two nos.
        {
            if (a>b)
            {
                return(a); 
            }
            return(b);
        }
   
        int biggest(int a , int b, int c) //for three nos.
        {
            int big1;
            if (a>b && a>c)
            {
                big1 = a;
            }
            else
            {
                if (b>c)
                {
                    big1 = b;
                }
                else
                {
                    big1 = c;
                }
            }
            return(big1);
        }   

        int biggest(int num[], int n) //for n numbers
        {
            int big1;
            big1=num[0];
            for(int i=0;i<n;i++)
            {
                if(num[i]>big1)
                big1=num[i];
            }
            return big1;
        }
    %>
    </body>
    </html>

8 comments :

  1. Excellent post!!!. The strategy you have posted on this technology helped me to get into the next level and had lot of information in it.
    Devops Training courses
    python Training in chennai
    Devops Training in Bangalore

    ReplyDelete
  2. The site was so nice, I found out about a lot of great things. I like the way you make your blog posts. Keep up the good work and may you gain success in the long run.
    Python Online training
    python Course institute in Chennai
    Python Course institute in Bangalore

    ReplyDelete
  3. All are saying the same thing repeatedly, but in your blog I had a chance to get some useful and unique information, I love your writing style very much, I would like to suggest your blog in my dude circle,keep up!!

    android training in chennai

    android online training in chennai

    android training in bangalore

    android training in hyderabad

    android Training in coimbatore

    android training

    android online training

    ReplyDelete
  4. This post is so interactive and informative.keep update more information...
    AWS Training in Tambaram
    AWS Training in Chennai

    ReplyDelete

FREE Hit Counters