Sunday, March 31, 2013

Java Basic Programs With Source Code and Comments

Before starting with Cryptography in Java, these are some of the basic programs that I built quickly to brush up. 


1. Hello Java Source Code : 


            public static void main(String[] args) {

                System.out.println("Hello Java ! ~ ! ~");

        }

       

    }


2. Simple Input/Output Program Source Code :


    import java.io.IOException;

    import java.io.InputStreamReader; 

    public class InputOutput_pranshu {

        public static void main(String[] args) throws IOException

        {

            System.out.println("Hello, What's your name??  ");

            BufferedReader BRobj = new BufferedReader(new InputStreamReader(System.in) );

            String name = BRobj.readLine();

            System.out.println("Hello " + name + ", have a nice day");

        }

       

    }



3.  If Else Decision Making Java Source code :


 /**
 *
 * @author pranshu
 */
 public class IfElse_pranshu {
    public static void main(String[] args) throws IOException
    {
        System.out.println("Hello, Please Enter your name : ");
        BufferedReader brobj = new BufferedReader(new InputStreamReader(System.in)); 
        String name = brobj.readLine();
        if("pranshu".equals(name))
        {
         System.out.println("Hello Pranshu, Please Enter your Password : ");
         String pass = brobj.readLine();
            if("java".equals(pass))
                System.out.println("Welcome Pranshu, Access Granted!!");
            else
                System.out.println("Access Denied, Wrong Password");
        }
         else
            System.out.println("Sorry, this User is NOT Allowed Access");
           
    }
            
}

4. Convert A Char to its ASCII value, Java Source Code :


/**
 *
 * @author root
 */
public class Ascii_pranshu {
    public static void main(String[] args) throws IOException
    {
        System.out.println("Enter the Char you want to convert to ASCII :");
        BufferedReader BRobj = new BufferedReader(new InputStreamReader(System.in));
        String text = BRobj.readLine();
        int c = text.charAt(0);
        System.out.println("The ASCII Code is " + c);
    }
    } 
 
 

No comments:

Post a Comment