Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

1.

TO DISPLAY A LINE

class Helloworld

public static void main (String args[ ])

System.out.println(“Hello world”);

2. ADDITION

class Addition
{
public static void main(String args[ ])
{
int x,y,z;
x=Integer.parseInt(ar[0]);
y=Integer.parseInt(a[1]);
z=x+y;
System.out.println(“Addition is=”+z);
}
}
3. AVERAGE

class Avg

public static void main(String args[ ])

int x, y, z, avg;

x=Integer.parseInt (a[0]);

y=Integer.parseInt (a[1]);

z=x+y;

Avg=z/2;

System.out.println(“Addition:”+z);

System.out.println(“Average”+Avg);

4. EVEN AND ODD NO

class Number

public static void main(String args[ ])

{
int x;

x=Integer.parseInt(args[0]);
if (x%2==0)
System.out.println(“The no is even”);
else
System.out.println(“The no is odd”);
}
}

5. TO SHOW POSITIVE AND NEGETIVE NO.

class Number

public static void main(String args[ ])

Int b;

b= Integer.parseInt (a[0]);

if(b><0)

System.out.println(“negative no”);

else

System.out.println(“positive no”);

}
6. EVEN NO.

class Even

public static void main(String args[ ])

System.out.println(“\n\n all even no up to 100”);

for(int x=0;x<=100;x=x+1)

if(x%==0)

System.out.println(“ “+x);

7. SUM

class Sum

public static void main(String args[ ])

int i=1

int sum=0;
while(i<=10)

sum=sum+i;

System.out.println(“the sum is “+”:”sum)

i++;

8. MULTIPICATION

class Multipication
{
public static void main(String args[ ])
{
int i=1;
int result;
do
{
result=i*5;
System.out.println(result);
i++;
}while(i<=10);
}
}
9. GREATEST

class Greatest

public static void main(String args[ ])

int x=10;

int y=10;

int z=30;

if (x>y && x>z)

System.out.println(“greatest is”t”:” +x);

else if (y>z && y>x)

System.out.println(“greatest is”+”:”+y);

else

System.out.println(“greatest is”+”:” +z);

10. REVERSE A STRING

class Rev

public static void main(String args[ ])

{
{

int i, n;

char c[ ]={‘I’;’S’;’T’};

String str=new String(c);

System.out.println(“Original string” +str);

System.out.println(“Reverse string”);

for (i=str.length()-1;i>=0;i--)

System.out.println(c[i]);

11. WRITE A PROGRAM TO ARRANGE THE STRING IN ASCENDING ORDER.

class abc

public static void main(String args[ ])

{string temp=” “;

for(i=0;i<args.length;i++)

{for(j=i+1;j<args.length;j++)

{if(args[i].compareTo(args[j])>0)

{temp=args[i];

args[i]=args[j];
args[j]=temp;

}}

System.out.println(“sorted list”);

for(i=0;i<args.length;i++)

System.out.println(args[i]);

}}

12. ARRAY

class Add
{
public static void main(String args[ ])
{
int month_days[ ];
month_days=new int[12];
month_days[0]=31;
month_days[1]=28;
month_days[2]=31;
month_days[3]=30;
month_days[4]=31;
month_days[5]=30;
month_days[6]=31;
month_days[7]=31;
month_days[8]=30;
month_days[9]=31;
month_days[10]=30;
month_days[11]=31;
System.out.println(“June has”+month_days[5]+”days”);
}}
13. STRING BUFFER

The String buffer Class

14.

15.

}
16.

}
17.

18.

19.

}
20.

You might also like