Walk Lightly on this PLANET and yet leave such a FOOTPRINT that cannot be erased for thousands of Years..!!!
Visit Codstech for Cyber Security related Posts !

Visitors

Monday, July 30, 2012

CJ-10: Print a message 5 times-While loop

Type the programs in NOTEPAD or DOS prompt itself, for Consol Application.
Type in NETBEANS or ECLIPSE for Window Application.
Here after , I am just typing the programs only..to know more about it , refer

Introduction to JAVA 

before doing any JAVA Programs.
***********************************************************************************************
import java.io.*;
class loop1
{
public static void main(String args[])
{
int i=0;
while(i<=4)
{
  System.out.println("Welcome to JAVA");
  i++;
}
}
}
=========================================================================
Output :
Welcome to JAVA
Welcome to JAVA
Welcome to JAVA
Welcome to JAVA



CJ-9: Odd or Even checking

Type the programs in NOTEPAD or DOS prompt itself, for Consol Application.
Type in NETBEANS or ECLIPSE for Window Application.
Here after , I am just typing the programs only..to know more about it , refer

Introduction to JAVA 

before doing any JAVA Programs.
***********************************************************************************************
import java.io.*;
class oddeven
{
public static void main(String arg[])
{
   int number;
   try
   {
      DataInputStream x=new DataInputStream(System.in);
      System.out.println("Enter a number :");
      number=Integer.parseInt(x.readLine());
      if(number%2==0)
      {
System.out.println("Number is Even");
      }
         else
         {
    System.out.println("Number is Odd");
}
    }
catch(Exception e)
{
}
}
}
=========================================================================
Output :
Enter a number :
7
Number is Odd


Sunday, July 29, 2012

CJ-8: Print Day according to number

Type the programs in NOTEPAD or DOS prompt itself, for Consol Application.
Type in NETBEANS or ECLIPSE for Window Application.
Here after , I am just typing the programs only..to know more about it , refer

Introduction to JAVA 

before doing any JAVA Programs.
***********************************************************************************************

import java.io.*;
class day
{
public static void main(String args[])
{
   int n;
   try
   {
DataInputStream x=new DataInputStream(System.in);
System.out.println("Enter a number upto 7");
n=Integer.parseInt(x.readLine());
  switch(n)
  {
                case 1:
System.out.println("Sunday");
break;
case 2:
System.out.println("Monday");
break;
case 3:
System.out.println("Tuesday");
break;
case 4:
System.out.println("Wednesday");
break;
case 5:
System.out.println("Thursday");
break;
case 6:
System.out.println("Friday");
break;
case 7:
System.out.println("Saturday");
break;
default:
System.out.println("Invalid Number");
break;
}
}
   catch(Exception e)
   {
   }
}
}
=========================================================================
Output :
Enter a number below 8
7
Saturday





Saturday, July 28, 2012

CJ-7: Check whether eligible for vote

Type the programs in NOTEPAD or DOS prompt itself, for Consol Application.
Type in NETBEANS or ECLIPSE for Window Application.
Here after , I am just typing the programs only..to know more about it , refer

Introduction to JAVA 

before doing any JAVA Programs.
***********************************************************************************************
import java.io.*;
class chk
{
public static void main(String args[])
{
int age;
try
{
   DataInputStream x=new DataInputStream(System.in);
   System.out.println("Enter age :");
   age=Integer.parseInt(x.readLine());
if(age>=18)
{
System.out.println("Eligible for vote");
}
else
{
System.out.println("Not Eligible for vote");
}
}
catch(Exception e)
{
}
}
}
========================================================================= 
Output : 
Enter age :
20
Eligible for vote.




CJ-6 : Four Calculations-Floating no

Type the programs in NOTEPAD or DOS prompt itself, for Consol Application.
Type in NETBEANS or ECLIPSE for Window Application.
Here after , I am just typing the programs only..to know more about it , refer

Introduction to JAVA 

before doing any JAVA Programs.
***********************************************************************************************
import java.io.*;
class math1
{
public static void main(String args[])
{
 float a,b,result;
 try
 {
  DataInputStream x=new DataInputStream(System.in);
  System.out.println("Enter the first number :");
  a=Float.parseFloat(x.readLine());
  System.out.println("Enter the second number :");
  b=Float.parseFloat(x.readLine());
   result=a+b;
   System.out.println("Addition = "+result);
   result=a-b;
   System.out.println("Subtraction = "+result);
   result=a*b;
   System.out.println("Multiplication = "+result);
   result=a/b;
   System.out.println("Division = "+result);
 }
 catch(Exception e)
 {
 }
}
}
========================================================================= 
Output : 
Enter the first number
12.24
Enter the second number
12.28
Addition=24.52
Subtraction =-0.03999996
Multiplication =150.30719
Division=0.99674267

Refer Four Calculations-Floating no also.




CJ-5 : Four Calculations-Integer no

Type the programs in NOTEPAD or DOS prompt itself, for Consol Application.
Type in NETBEANS or ECLIPSE for Window Application.
Here after , I am just typing the programs only..to know more about it , refer

Introduction to JAVA 

before doing any JAVA Programs.
***********************************************************************************************
import java.io.*;
class math
{
public static void main(String args[])
{
int a,b,result;
try
{
DataInputStream x=new DataInputStream(System.in);
System.out.println("Enter the first number :");
a=Integer.parseInt(x.readLine());
System.out.println("Enter the second number :");
b=Integer.parseInt(x.readLine());
result=a+b;
System.out.println("Addition = "+result);
result=a-b;
System.out.println("Subtraction = "+result);
result=a*b;
System.out.println("Multiplication = "+result);
result=a/b;
System.out.println("Division = "+result);
}
catch(Exception e)
{
}
}
}
========================================================================= 
Output : 
Enter the first number
8
Enter the second number
4
Addition=12
Subtraction =4
Multiplication =32
Division=2


Refer Four Calculations-Floating no also.







CJ-4 : Sum(user defined values)

Type the programs in NOTEPAD or DOS prompt itself, for Consol Application.
Type in NETBEANS or ECLIPSE for Window Application.
Here after , I am just typing the programs only..to know more about it , refer

Introduction to JAVA 

before doing any JAVA Programs.
*********************************************************************************************
Refer Sum(predefined values) also.
*********************************************************************************************
import java.io.*;
class Adduser 
{
public static void main(String args[]) 
{   
     int a,b,sum;
     try
{
DataInputStream x=new DataInputStream(System.in);
System.out.println("Enter two numbers :");
a=Integer.parseInt(x.readLine());
b=Integer.parseInt(x.readLine());
sum=a+b;
System.out.println("Addition= "+sum);
}
   catch(Exception e)
   {
   }
}
}
========================================================================= 
Output : 
Enter two numbers :
30
20
Addition=50.



CJ-3 : Sum(predefined values)

Type the programs in NOTEPAD or DOS prompt itself, for Consol Application.
Type in NETBEANS or ECLIPSE for Window Application.
Here after , I am just typing the programs only..to know more about it , refer

Introduction to JAVA 

before doing any JAVA Programs.
************************************************************************************
Refer Sum(user defined values) also.
************************************************************************************
class Add 
{
public static void main(String args[]) 
{   
     int a,b,c;
     a=20;
     b=40;
     c=a+b;
     System.out.println("Addition="+c);
}
}
=========================================================================
Output : Addition=60.



Friday, July 27, 2012

CJ-2 : Welcome Program-Window Application


For a complete list, click JAVA


Refer Introduction to JAVA before going through your first program.

And for theory part , refer "Some Theory Part in JAVA"

=========================================================================
class firstprogram
{
public static void main(String args[ ])
{
System.out.println("Hai...Welcome...");
}
}
=========================================================================
  • Here, firstprogram is the program name.(See, class firstprogram ).The name after declaring the class , is the program name.We have to use the same name , while saving.
  • Also note the capital letters of the words String and System. They are case sensitive.
Instead of typing the program  in NOTEPAD or DOS prompt , here , we are using some softwares like NETBEANS or ECLIPSE etc..
========================================================================= 

(A) : Familier with NETBEANS platform:

Download NetBeans IDE 


Download NetBeans from here for free. (You need JDK or Java Development Kit for installing NetBeans . If you have no Java platform on your system , download from here (which contains JDK+NetBeans ) .



When clicking this , we get  :


We will get a window as shown below :




Click ; File--> New Project.
Then we can see,



Select JAVA from Categories;  and JAVA APPLICATION from Projects.
Click , Next .
Then , another window will appear as : 


Give a project name , and click Finish.
Then we can see the NetBeans IDE for typing the program.It will look like ;



In our program , we need to type the last println statement only.
The sentenses like /**/  does not tken by the Compiler.So, no need to bother about the extra sentenses you see there.
After typing the println statement to display "Hai....Welcome..." , we have to run it.
right click on the page , and select Run the File , from the drop down menu( or , select from the main menu....or , you can use ShiftF6).
The output will displayed in the bottom....as ; 



=========================================================================

(B) : Familier with ECLIPSE platform:

When clicking this , we get  :  


After giving the details as done before , we can see the Eclipse IDE for typing the program.
I just did the programs and you can see the output there.
(It is also more or less same as NETBEANS , so i just skip the steps for taking the Eclipse IDE here....)