banner

Tuesday, August 30, 2016

PROGRAM DEMO : ARRAYS

  public class ArrayDemo { public static void main ( String [] args) { int n = Integer . parseInt(args[ 0 ]); ... thumbnail 1 summary
 
public class ArrayDemo {
    public static void main(String[] args) {
        int n = Integer.parseInt(args[0]);

        // initialize to random values between 0 and 1
        double[] a = new double[n];
        for (int i = 0; i < n; i++) {
            a[i] = Math.random();
        }

        // print array values, one per line
        System.out.println("a[]");
        System.out.println("-------------------");
        for (int i = 0; i < n; i++) {
            System.out.println(a[i]);
        }
        System.out.println();
        System.out.println("a = " + a);
        System.out.println();

        // find the maximum
        double max = Double.NEGATIVE_INFINITY;
        for (int i = 0; i < n; i++) {
            if (a[i] > max) max = a[i];
        }
        System.out.println("max = " + max);


        // average
        double sum = 0.0;
        for (int i = 0; i < n; i++) {
            sum += a[i];
        }
        System.out.println("average = " + sum / n);

        // copy to another array
        double[] b = new double[n];
        for (int i = 0; i < n; i++) {
            b[i] = a[i];
        }

        // reverse the order
        for (int i = 0; i < n/2; i++) {
            double temp = b[i];
            b[i] = b[n-i-1];
            b[n-i-1] = temp;
        }

        // print array values, one per line
        System.out.println();
        System.out.println("b[]");
        System.out.println("-------------------");
        for (int i = 0; i < n; i++) {
            System.out.println(b[i]);
        }
        System.out.println();


        // dot product of a[] and b[]
        double dotProduct = 0.0;
        for (int i = 0; i < n; i++) {
            dotProduct += a[i] * b[i];
        }
        System.out.println("dot product of a[] and b[] = " + dotProduct);

    }

}


Monday, August 29, 2016

PE 2 : String Manipulation

/*  *Write a Java program that reads a string from the keyboard, and outputs the string twice in a row, first all uppercase and next al... thumbnail 1 summary

/*
 *Write a Java program that reads a string from the keyboard, and outputs the string twice in a row, first all uppercase and next all lowercase.
If, for instance, the string “Hello" is given, the output will be “HELLOhello"
 */

TIP : Use the Scanner and String Methods

Sunday, August 28, 2016

PROGRAM DEMO :STRING METHODS

Program to illustrate all string methods : // Java code to illustrate different constructors and methods // String class. import... thumbnail 1 summary

Program to illustrate all string  methods:
// Java code to illustrate different constructors and methods 
// String class.
 
import java.io.*;
import java.util.*;
class Test {
        public static void main (String[] args){
        String s= "MarianKuttikkanam";
        // or String s= new String ("MarianKuttikkanam");
 
        // Returns the number of characters in the String.
        System.out.println("String length = " + s.length());
 
        // Returns the character at ith index.
        System.out.println("Character at 3rd position = "
                           + s.charAt(3));
 
        // Return the substring from the ith  index character
        // to end of string
        System.out.println("Substring " + s.substring(3));
 
        // Returns the substring from i to j-1 index.
        System.out.println("Substring  = " + s.substring(2,5));
 
        // Concatenates string2 to the end of string1.
        String s1 = "Marian";
        String s2 = "Kuttikkanam";
        System.out.println("Concatenated string  = " +
                            s1.concat(s2));
 
        // Returns the index within the string
        // of the first occurrence of the specified string.
        String s4 = "Information Formation Transformation";
        System.out.println("Index of Transformation " + 
                              s4.indexOf("Transformation")); 
        // Returns the index within the string of the
        // first occurrence of the specified string,
        // starting at the specified index.
        System.out.println("Index of a  = " + 
                           s4.indexOf('a',3));
 
        // Checking equality of Strings
        Boolean out = "Marian".equals("marian");
        System.out.println("Checking Equality  " + out);
        out = "Marian".equals("Marian");
        System.out.println("Checking Equality  " + out);
 
        out = "Marian".equalsIgnoreCase("mArIan ");
        System.out.println("Checking Equality" + out);
 
        int out1 = s1.compareTo(s2);
        System.out.println("If s1 = s2" + out);
 
        // Converting cases
        String word1 = "MARIAN";
        System.out.println("Changing to lower Case " +
                            word1.toLowerCase());
 
        // Converting cases
        String word2 = "marian";
        System.out.println("Changing to UPPER Case " + 
                            word1.toUpperCase());
 
        
    } 
}

Thursday, August 25, 2016

PROGRAMMING EXERCISE 1

Write an application that asks the user to enter two integers, obtains them from the user and prints their sum, product, difference a... thumbnail 1 summary


Write an application that asks the user to enter two integers, obtains them from the user and prints their sum, product, difference and quotient (division). (Use the Scanner Class )

Wednesday, August 24, 2016

PROGRAM DEMO : SCANNER

// Java program to read data of various types using Scanner class. import java.util.Scanner ; public class ScannerDemo1 { publ... thumbnail 1 summary

// Java program to read data of various types using Scanner class.
import java.util.Scanner;
public class ScannerDemo1
{
    public static void main(String[] args)
    {
        // Declare the object and initialize with
        // predefined standard input object
        Scanner sc = new Scanner(System.in);
 
        // String input
        String name = sc.nextLine();
 
        // Character input
        char gender = sc.next().charAt(0);
 
        // Numerical data input
        // byte, short and float can be read
        // using similar-named functions.
        int age = sc.nextInt();
        long mobileNo = sc.nextLong();
        double cgpa = sc.nextDouble();
 
        // Print the values to check if input was correctly obtained.
        System.out.println("Name: "+name);
        System.out.println("Gender: "+gender);
        System.out.println("Age: "+age);
        System.out.println("Mobile Number: "+mobileNo);
        System.out.println("CGPA: "+cgpa);
    }
}

SURVEY RESPONSES

This survey was conducted to know the background of the students who are the participants of this course. The questions ranged from a ... thumbnail 1 summary

This survey was conducted to know the background of the students who are the participants of this course. The questions ranged from a self assessment of their Java Programming skills to the details of their previous software project.

Some responses which could be graphically projected are shown below.





Sunday, August 21, 2016

WELCOME

This blog will act as the one stop information center of your Java Programming Lab. First let me find out some information about your b... thumbnail 1 summary

This blog will act as the one stop information center of your Java Programming Lab.
First let me find out some information about your background.Please fill this form