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( );}...

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