Lagrange’s Interpolation Formula

The java implementation of Lagrange’s Interpolation Formula

import java.util.*;

public class Lagrange {
    
    
    public static double xToY (double x [], double y [], double xx) {
        
        int i, j , size = x.length;
        double  sum = 0, term;
        
        for(i = 0; i < size; ++i) {
            term = y[i];
            for(j = 0; j < size; ++j) {
                if( i != j)
                    term *= (xx - x [j]) / (x[i] - x[j]); 
            }
            sum += term;
        }
        return sum;
    }
    
    public static double yToX (double x1 [], double y1 [], double yy) {
        
        int i, j, size = x1.length;
        double term,sum = 0 ;
        
        for(i = 0; i < size; ++i){
            term = x1[i];
            for(j = 0; j < size; ++j){
                if(i != j)
                    term *= (yy - y1[j]) / (y1[i] - y1[j]);
            }
            sum += term ; 
        }
        return sum;
    }
    
    public static void main (String args []) {
        Scanner sc = new Scanner (System.in);
        
        /* For finding yy */
        double x [] = {3 , 4, 5, 6, 7, 8, 9};
        double y [] = {0 , 1, 3, 7, 13, 22, 34};
        double xx = 10;
        
        
        System.out.println(xToY(x, y, xx));
        System.out.println();
        
        /* For finding xx */
        double x1 [] = {0.46, 0.47, 0.48, 0.49};
        double y1 [] = {0.4846555, 0.4937452, 0.5027498, 0.5116683};
        double yy = 0.5;
        
        System.out.println(yToX(x1, y1, yy));
        System.out.println();
        
    }
}
Advertisements

Fun With Unicode!

Run this code in java IDE like DrJava! and see the output

\u0070\u0075\u0062\u006C\u0069c class A \u007B
    \u0070\u0075\u0062\u006C\u0069c \u0073\u0074\u0061\u0074\u0069\u0063 \u0076\u006F\u0069\u0064 \u006D\u0061\u0069\u006E \u0028\u0053\u0074\u0072\u0069\u006E\u0067 \u0061\u0072\u0067\u0073 \u005B\u005D\u0029 \u007B
    \u0053\u0079\u0073\u0074\u0065\u006D.\u006F\u0075\u0074.\u0070\u0072\u0069\u006E\u0074\u006C\u006E\u0028\u0022\u0048\u0065\u006C\u006C\u006F \u0057\u006F\u0072\u006C\u0064\u0022\u0029\u003B
    \u007D
    \u007D

Introduction

java

Java is a programming language originally developed by James Gosling at Sun Microsystems (which is now a subsidiary of Oracle Corporation) and released in 1995 as a core component of Sun Microsystems’ Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities. Java applications are typically compiled to bytecode (class file) that can run on any Java Virtual Machine (JVM) regardless of computer architecture. Java is a general-purpose, concurrent, class-based, object-oriented language that is specifically designed to have as few implementation dependencies as possible. It is intended to let application developers “write once, run anywhere”. Java is currently one of the most popular programming languages in use, and is widely used from application software to web applications. The original and reference implementation Java compilers, virtual machines, and class libraries were developed by Sun from 1995. As of May 2007, in compliance with the specifications of the Java Community Process, Sun relicensed most of its Java technologies under the GNU General Public License. Others have also developed alternative implementations of these Sun technologies, such as the GNU Compiler for Java, GNU Classpath, and Dalvik.

wikipedia

1st thing you should do that download the jdk (java development kit) from here and then download any of the IDE.  For java you should know the java documentation (javadoc) and the Java Language Specification (JLS).

There were five primary goals in the creation of the Java language:

1. It should be “simple, object oriented, and familiar”.
2. It should be “robust and secure”.
3. It should have “an architecture-neutral and portable environment”.
4. It should execute with “high performance”.
5. It should be “interpreted, threaded, and dynamic”.

There are several IDE (Integrated development environment) for java like

Eclipse, NetBeans, DrJava, JIPE, Gel, BlueJ

In this website we are going to cover JAVA SE(wiki), JAVA SE(oracle). Before starting coding you should gone through following pages.

1. Java Code Convention’s Click Here
2. Java data types Click Here
3. Java operators Click Here

mascot

Duke, the Java mascot

Insertion Sort (JAVA)

public class InsertionSort{

    public static void main (String [] args){

        int [] ar = {213,34,3,23,2,231,1,323,35,43,3,4,56,0};

        for (int i = 1; i < ar.length; ++i){

            int key = ar[i];

            int j = i - 1;

            while (j >= 0 && key < ar[j]){

                  ar[j+1] = ar[j];

                  --j;

            }

            ar[j+1] = key;

        }

        for (int i = 0; i < ar.length; i++)
            System.out.println(ar[i]);

    }

}

Big Integer

Here are some problem numbers related to Big Integer from UVA

http://uva.onlinejudge.org/

288
290
324
343
355
374
389
424
446
485
495
568
619
623
636
713
748
10007
10013
10023
10083
10814
10106
10183
10219
10220
10303
10334
10473
10494
10523
10519
10551
10579
10606
10669
10814
10925
10992
11161
11438

Series (JAVA)

//Author:  S.Mahbub - uz - zaman
//1 2 4 7 11 16 22 29 37 46 56 ……. Series
//05.05.2010

public class Series{
    public static void main(String args[]){
        int sum=1;
        for(int i=1;i<=100;++i){
            System.out.print(sum+" ");
            sum=sum+i;
        }
        System.out.println();
    }
}