Tuesday, 4 June 2013

SOME BASIC PROGRAMS

today we were bored and exhausted practical time was good but theory was boring
we did casting conversions
run time input methods
array

 Q)MAKE A PYRAMID
*
**
***
****
ANS:

class Pyramid
{
public static void main(String arg[])
{int i,j;
for(i=0;i<4;i++)
{
for(j=0;j<=i;j++)
{System.out.print("*");
}
System.out.println("");
}}}



Q)CHECK IF NO IS PALINDROME
ANS:
class Palindrome
{
public static void main(String arg[])
{
int a,b,c,d;
a=Integer.parseInt(arg[0]);
b=Integer.parseInt(arg[1]);
c=Integer.parseInt(arg[2]);
d=Integer.parseInt(arg[3]);
if((a==d)&&(b==c))
{
System.out.println("no is palindrome");}
else
{
System.out.println("no is not palindrome");}
}}


Q)PRINT NO FROME 0 TO N
ANS:
class Print0ton
{
public static void main(String arg[])
{
int a;
a=Integer.parseInt(arg[0]);
for(int i=a;i>=0;i--)
{
System.out.println(i);
}
}}

Q)TO REVERSE A GIVEN NO
 ANS:
class Reverse
{
public static void main(String arg[])
{
int a,b,c,d;
a=Integer.parseInt(arg[0]);
b=Integer.parseInt(arg[1]);
c=Integer.parseInt(arg[2]);
d=Integer.parseInt(arg[3]);
System.out.print(" "+d+" "+c+" "+b+" "+a);
}}

Q) WAP IN JAVA TO FIND SMALLEST OF NO.S
ANS
class Smallest
{
public static void main(String arg[])
{
int a,b,c,d;
a=Integer.parseInt(arg[0]);
b=Integer.parseInt(arg[1]);
c=Integer.parseInt(arg[2]);
if((a<=b)&&(a<=c))
System.out.println("smallest no is "+a);
else if((b<=a)&&(b<=c))
System.out.println(" smallest no is"+b);
else
System.out.println("smallest no is "+c);
}}




No comments:

Post a Comment