Monday, 1 August 2011

The if decision structure

The if statement evaluates a condition and if the result is true then it runs the line of code that follows it. Here is an example of how to test if the value of a variable called I is equal to 5 :public class Decisions{               public static void main( String [ ] args )                {                int i = 5 ;              ...

How to use Command-Line Arguments

Using Command-Line ArgumentsHelps us to pass information into a program when it is runclass CommandLine {public static void main (String args [ ] ) {for (int i= 0; I < args.length ; i ++ )System.out.println(“ args [ “ + i + “ ] ; “ + args [ i ]) ;}} To execute a program, we write from the command prompt: java CommandLine this is a test 100...

Simple program to arrange the citynames in ascending order

Simple program to arrange the citynames in ascending order class stasc{                    public static void main (String args [ ])                     {                                       ...

arrange the numbers in descending order

class comm.{                    public static void main (String args [] )                    {                    int I,j,k ;                    k= args.length;                   ...

Friday, 29 July 2011

How to run Java program

A First Simple Program /* This is a simple program Call this file “Example.java”. */ Class Example { //Your program begins with a call to main (). Public static void main (String args[]) { System.out.println (“This is a simple Java program “); } } Entering the program -The name of a source file is very important -In Java, all code must reside inside a class. By convention ,the name of that class should match the name of the file that holds the program -A source file use the .java filename extension Compilling the Program C:>\javac Example...

Features of java programming language

Compiled and interpreted Platform – IndependentObject – OrientedRobust and SecureDistributedMultithreaded Dynamic and Extensible Compiled and interpreted:-                Usually a computer language is either compiled or interpreted. Java combines both these approaches thus making Java a two stage system. First, Java compiler translates sources code into what is known as byte code instruction. Byte codes are not machine instructions and therefore, in the second stage. Java...

Thursday, 28 July 2011

Program to enter a 5*5 matrix and display it

class matrix{Public static void main (String arg []){int two [] [] = new int [5] [5];{int i,j,k =0;for (i= 0; i<5 ; i++) {for (j=0 ; j<5; j++){Two [i] [j] = k;k++;} }for (i=0; k=5 ;i++){for (j=0; j<5 ; j++){System.out.print( two [i] [i] + “  “ );}System.out.println( );}...

A simple program to arrange the 10 nos. in ascending order using array.

class ASC{Public static void main (String arg[]){int I,j,k;int a[] ={10,12,18,16,3};for (i=1;i<5;i++){for(j=0;j<=3;j++){if(a[j] > = a [ j+ 1]){k=a [j];a[j]=a[j+1]a[j+1]=k;}}}for(i=0;i<5;i++){System.out.println (a [i]);...

A simple program to find the average of 10 nos. using array class Arg

class Arg{Public static void main (string arg []){int no []= { 10 ,12 , 14 ,16 ,18 ,20 ,22, 24 ,26 28);int result = 0;for (i=0; i<10;i++)result =result + no [i];System.out.println(“Average is “ +result/10)...

Wednesday, 27 July 2011

Structure of JAVA program

 A JAVA program may contains many classes of which only one class defines a main method. Classes contain data members and methods that operated on the data members of the class. Methods may contain data type declaration and executed statements. To write a Java program, we first define classes and then put them together. A Java program may contain one or more sections...

Simple program for printing the following chatuskon upto given value and print the patter for “*”

                        *                                                                                                   ...

simple program for printing the following pyramid using for loop

                                                            1                  2                ...

Program for Printing the following pyramid

12 23 3 34 4 4 4n n n ………………n class series{ Public static void main (String args[]){ int i,j,n;n=50; for(i=1;i<=50; i++ ) { for(j=1;j<=1;j++) { system.out.print (i); } system.out.println (“ “); ...

Simple program for making Pyramid using only while loop

11 2 1 2 31 2 3 41 2 3 4…..N class series{ Public static void main (String args []) { int N=10; i=1; j=1;while( i<N) { j=1;while(J<=i) { System.out.println(j);J++; } System.out.println(“”);i++; }}} ...

Page 1 of 712345Next
Twitter Delicious Facebook Digg Stumbleupon Favorites More