1. My First Java Program: Print a Message "Hello World"

My First Java Program: Print a Message "Hello World"

class HelloWorld
{
public static void main(String...s)
{
System.out.println("Hello World");
}
}

2. Java program to swap two numbers


Java program to swap two numbers

class Swap
{
public static void main(String...s)
{
int a,b,temp;
a=Integer.parseInt(s[0]);
b=Integer.parseInt(s[1]);

System.out.println("\nBefore Swap:\n"+"a="+a+"\tb="+b);

temp=a;
a=b;
b=temp;

System.out.println("\nAfter Swap:\n"+"a="+a+"\tb="+b);
}
}

3. Java program to swap two numbers without using temp variable


Java program to swap two numbers without using temp variable

class Swap
{
public static void main(String...s)
{
int a,b;
a=Integer.parseInt(s[0]);
b=Integer.parseInt(s[1]);

System.out.println("\nBefore Swap:\n"+"a="+a+"\tb="+b);

a=a+b;
b=a-b;
a=a-b;

System.out.println("\nAfter Swap:\n"+"a="+a+"\tb="+b);
}
}

4. Java program to convert given number of days into months and days


Java program to convert given number of days into months and days

class Days
{
public static void main(String...s)
{

int n,m,d;
n=Integer.parseInt(s[0]);

m=n/30;
d=n%30;

System.out.println(n+" days"+" = "+m+" months "+"and "+d+" days");
}
}

0 comments :

Please Enter best of your Comments