0% found this document useful (0 votes)
109 views109 pages

Untitled

The document contains sample code solutions to common programming questions involving basic Java programs. The programs demonstrate how to: 1) Swap two variables with and without using a third variable. 2) Find the largest and smallest of two or more numbers using conditional operators. 3) Check if a number is even or odd, divisible by 7, and other basic conditional checks.

Uploaded by

Vasu Gadu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
109 views109 pages

Untitled

The document contains sample code solutions to common programming questions involving basic Java programs. The programs demonstrate how to: 1) Swap two variables with and without using a third variable. 2) Find the largest and smallest of two or more numbers using conditional operators. 3) Check if a number is even or odd, divisible by 7, and other basic conditional checks.

Uploaded by

Vasu Gadu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 109

PROGRAMMING QUESTIONS :

________________________________
BASIC PROGRAMS
---------------
1) WAP TO SWAP TWO VARIABLE WITH USING THIRD VARIABLE?

-----------------------------------------------------------------------------------
------------------------
ANSWER:==== class Swap{
public static void main(String[] args){
int a=12,b=23,c;
c=a;
a=b;
b=c;
System.out.println("a="+a);//o/p:a=23
System.out.println("b="+b);//o/p:b=12
}
}
___________________________________________________________________________________
_________________________
2)WAP TO SWAP TWO VARIBLES WITHOUT USING ANOTHER VARIABLE ?

-----------------------------------------------------------------------------------
----------------------------
Answer:=== class Swap_var{
public static void main(String[] args){
int a=12,b=23;
b=a+b;
a=b-a;
b=b-a;
System.out.println("a="+a);//o/p:a=23
System.out.println("b="+b);//o/p:b=12
}
}
___________________________________________________________________________________
___________________________________

3)WAP TO PRINT LARGEST OF TWO NUMBERS WITH THE HELP OF


CONDITIONAL OPERATOR ?

-----------------------------------------------------------------------------------
--------------------------------
Answer:=== class Largest{
public static void main(String[] args){
int a=123,b=233;
String res=(a>b)?a:b;
System.out.println("largest value
of three numbers...:"+res);
}
}
___________________________________________________________________________________
______________________________________

4)WAP TO CHECK GIVEN NUMBER IS EVEN OR ODD ?

-----------------------------------------------------------------------------------
---------------------------------------
Answer:==== class EvenOrOdd{
public static void main(String[] args){
int num=123454;
if(num%2==0){

System.out.println("given number is evrn number:"+num);


}
else{

System.out.println("given number is odd number :"+num);


}
}
}

___________________________________________________________________________________
______________________________________

5)WAP TO CHECK WHETHER GIVEN NUMBER IS DIVISABL BY 7 OR NOT


?

-----------------------------------------------------------------------------------
----------------------------------------
Answer:==== class Divisable{
public static void main (String[] args){
int num=1400;
if(num%7==0){
System.out.println("given
number is divioded by 7:"+num);
}
else{

System.out.println("given number is not divided by 7:"+num);


}
}
}

___________________________________________________________________________________
____________________________________________________

6)WAP TO CHECK LARGEST OF THREE NUMBERS ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------

Answer:===
class Learg{
public static void
main(String[] args){
int
a=123,b=234,c=237;
if(a>b){

if(a>c){

System.out.println("a is leargest number :"+a);

}
else{
System.out.println(" c is leargest number :"+c);

else{

if(b>c){

System.out.println("b is leargest number :"+b);

else{

System.out.println("c is leargest number :"+c);

}
}
}
}
___________________________________________________________________________________
______________________________________

7)WAP TO CHECK SMALLEST OF THREE NUMBERS ?

-----------------------------------------------------------------------------------
----------------------------------------------------

Answer:===
class Small{
public static void main(String[] args){
int
a=123,b=234,c=237;
if(a<b){

if(a<c){

System.out.println("a is smallest number :"+a);

}
else{

System.out.println(" c is smallest number :"+c);

else{

if(b<c){

System.out.println("b is smallest number :"+b);


}

else{

System.out.println("c is smallest number :"+c);

}
}
}
}

___________________________________________________________________________________
_____________________________________________

CONDITIONAL OPERATOR:
----------------------
-----------------------------------------------------------------------
---------------------------------------------

1)WAP TO PRINT LARGEST OF 5 NUMBERS ?

-----------------------------------------------------------------------------------
-----------------------------------------------
Answer:=== class Largestnum{
public static void
main(String[] args){
int
a=101,b=20,c=30,d=40,e=50;
int res=(a>b)?((a>c)?
a:c):((b>c)?b:c);
String res1=(d>e)?
((d>res)?"d="+d:"res="+res):((e>res)?"e="+e:"res="+res);

System.out.println("largest number is "+res1);


}
}

___________________________________________________________________________________
________________________________________________________

2)WAP TO PRINT SMALLEST OF 4 NUMBERS ?

-----------------------------------------------------------------------------------
-------------------------------------------------

Answer:=== class Smallestnum{


public static void
main(String[] args){
int a=101,b=20,c=30,d=40;
int res=(a<b)?((a<c)?a:c):
((b<c)?b:c);
String
res1=(d<res)?"d="+d:"res="+res;

System.out.println("smallest number is "+res1);


}
}

___________________________________________________________________________________
_______________________________________________________

3)WAP TO PRINT SMALLEST OF 7 NUMBERS ?

-----------------------------------------------------------------------------------
-----------------------------------------------------
Answer:=== class Largestnum1{
public static void main(String[] args){
int a=101,b=20,c=30,d=40,e=50,f=122,g=111;
int res=(a>b)?((a>c)?
a:c):((b>c)?b:c);
int res1=(d>e)?((d>f)?
d:f):((e>f)?e:f);
int res2=(res>res1)?
((res>g)?res:g):((res1>g)?res1:g);

System.out.println("largest number is "+res2);


}
}

___________________________________________________________________________________
____________________________________________________

4)WAP TO PRINT LARGEST OF 7 NUMBER ?

-----------------------------------------------------------------------------------
---------------------------------------------------

Answer:=== class Smallestnum1{


public static void main(String[] args){
int a=101,b=20,c=30,d=40,e=50,f=122,g=111;
int res=(a<b)?((a<c)?
a:c):((b<c)?b:c);
int res1=(d<e)?((d<f)?
d:f):((e<f)?e:f);
int res2=(res<res1)?
((res<g)?res:g):((res1<g)?res1:g);

System.out.println("largest number is "+res2);


}
}

___________________________________________________________________________________
_______________________________________________

IF-ELSE:
---------
-----------------------------------------------------------------------------
-----------------------------------

1)WAP TO CHECK LARGEST OF TWO NUMBERS ?


-----------------------------------------------------------------------------------
------------------------------------------------------

Answer:=== class Learge{


public static void main(String[] args){
int a=10,b=111;
if(a>b){
System.out.println("a is learge
value :"+a);
}
else{
System.out.println("b is
learge value :"+b);
}
}
}

___________________________________________________________________________________
___________________________________________________________

2)WAP TO CHECK SMALLEST OF TWO NUMBERS ?

-----------------------------------------------------------------------------------
-----------------------------------------------------

Answer:===class Small{
public static void main(String[] args){
int a=111,b=12232;
if(a<b){
System.out.println("a is samll
number :"+a);
}
else{
System.out.println("b is small
number :"+b);
}
}
}

___________________________________________________________________________________
________________________________________________________

3)WAP TO CHECK GIVEN NUMBER IS EVEN


OR ODD ?

-----------------------------------------------------------------------------------
-------------------------------------------------------
Answer:==== class EvenOdd{
public static void main(String[]
args){
int num=12233;
if(num%2==0){
System.out.println("given
number is even number :"+num);
}
else{

System.out.println("given number is odd number :"+num);


}
}
}

___________________________________________________________________________________
______________________________________________________________

4)WAP TO CHECK THE LAST DIGIT IS 5 OR NOT


?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------
Answer:====class Digite{
public static void main(String[] args){
int num=12345;
if(num%10==5){
System.out.println("given
number is last digites is 5:"+num);
}
else{

System.out.println("given number is last digites is not 5:"+num);


}
}
}

___________________________________________________________________________________
________________________________________________________________________

5)WAP TO PRINT LAST DIGIT OF THE NUMBER ?

-----------------------------------------------------------------------------------
-------------------------------------------------------------------------

Answer:===class LastDigite{
public static void main(String[] args){
int num=123453;
if(num>0){
int r=num%10;
System.out.println("last
diogite of given number:"+r);
}
}
}

___________________________________________________________________________________
______________________________________________________________________

6)WAP TO CHECK WHETHER A CHARACTER IS ALPHABET


OR NOT ?

-----------------------------------------------------------------------------------
----------------------------------------------------------------------
Answer:===class Alphabet{
public static void main(String[] args){
char ch='/';
if((ch>'a' && ch<'z') || (ch>'A' &&
ch<'Z')){
System.out.println("given
charector is alphabet charector:"+ch);
}
else{
System.out.println("given
charector is not alphabet charector:"+ch);

}
}
}

___________________________________________________________________________________
_________________________________________________________________________

7)WAP TO CHACK WHETHER A


GIVEN CHARACTER IS A SPECIAL CHARACTER OR NOT

-----------------------------------------------------------------------------------
-------------------------------------------------------------------------------
Answer:===class SpicalCharecor{
public static void main(String[] args){
char ch='/';
if((ch>'a' && ch<'z') || (ch>'A' &&
ch<'Z') ||(ch>'0' && ch<'9')){
System.out.println("given
charector is not spical charector:"+ch);
}
else{
System.out.println("given
charector is spcial charector:"+ch);

}
}
}

___________________________________________________________________________________
_____________________________________________________________________________

8)WAP TO PRINT MIDDLE NUMBER


FROM 3 NUMBERS ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------
Answer:====class Middlenum{
public static void main(String[] args){
int a=12,b=125,c=17;
if((a<b && c>b) || (c<b && a>b)){
System.out.println("b is middle
number :"+b);
}
else if(( a<c && b>c) || (b<c
&& a>c)){
System.out.println("c is middle
number :"+c);
}
else{
System.out.println("a is
middle number :"+a);
}
}
}

___________________________________________________________________________________
____________________________________________________________________________

9)WAP TO CHECK WHETHER THE


ASCII VALUE OF CHARACTER IS EVEN OR ODD ?

-----------------------------------------------------------------------------------
--------------------------------------------------------------------------

Answer:====class Ascii{
public static void main(String[] args){
char ch='/';
int a=ch;
if(ch%2==0){
System.out.println("given charector
is ascii value is even number:"+a);
}
else{
System.out.println("given charector
is ascii value is odd number:"+a);
}
}
}

___________________________________________________________________________________
________________________________________________________________________________

10)WAP TO PRINT LARGEST OF 5


NUMBERS ?

-----------------------------------------------------------------------------------
-------------------------------------------------------------------------------
Answer:====class LeargeOf5{
public static void main(String[] args){
int a=12,b=13,c=24,d=34,e=111;
int learge=a;
if(learge<b){
learge=b;
}
if(learge<c){
learge=c;
}
if(learge<d){
learge=d;
}
if(learge<e){
learge=e;
}
System.out.println("largest value
of 5 numbers is: "+learge);
}
}

___________________________________________________________________________________
________________________________________________________________________________

11)WAP TO PRINT SMALLEST OF 5


NUMBERS ?

-----------------------------------------------------------------------------------
-------------------------------------------------------------------------------

Answer:====class SmallOf5{
public static void main(String[] args){
int a=12,b=13,c=24,d=34,e=111;
int small=a;
if(small>b){
small=b;
}
if(small>c){
small=c;
}
if(small>d){
small=d;
}
if(small>e){
small=e;
}
System.out.println("largest value
of 5 numbers is: "+small);
}
}

___________________________________________________________________________________
_____________________________________________________________________________

12)WAP TO PRINT ASCENDING


ORDER OF THREE NUMBERS ?

-----------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Answer:===class AssendingO3{
public static void main(String[] args){
int a=123,b=252,c=121;
if((a>b && b>c)||(c>b &&b>a)){
if(a<c){
System.out.println("asending
order of three numbers= "+"a:"+a+" b:"+b+ " c:"+c);
}
else{

System.out.println("asending order of three numbers= "+"c:"+c+" b:"+b+ "


a:"+a);
}
}
else if((a>c && c>b)||(b>c &&
c>a)){
if(a<b){

System.out.println("asending order of three numbers = "+"a:"+a+" c:"+c+ "


b:"+b);
}
else{

System.out.println("asending order of three numbers = "+"b:"+b+" c:"+c+ "


a:"+a);
}
}
else {

if(b<c){

System.out.println("asending order of three numbers = "+ "b:"+b+" a:"+a+ "


c:"+c);

}
else{

System.out.println("asending order of three numbers= "+"c:"+c+" a:"+a+ "


b:"+b);
}
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
___

SWITCH
-------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---

1)WAP TO CHECK GIVEN


CHARACTER VOWEL OR NOT ?

-----------------------------------------------------------------------------------
----------------------------------------------------------------------------
Answer:===class Vowel{
public static void main(String[] args){
char ch='Z';
switch(ch){
case 'a':
case 'e':
case 'i':
case 'o':
case 'u':
{ System.out.println("given charector is lower case vowel:"+ch); break;}
case 'A':
case 'E':
case 'I':
case 'O':
case 'U':
{ System.out.println("given charector is upper case vowel :"+ch); break;}
default:{

System.out.println("given charector is not vowel:" +ch);


}
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
_____

2)WAP TO PRINT DAY NAME BY READING


THE NUMBER OF THE DAY ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------
Answer:====class Week{
public static void main(String[] args){
int num=7;
switch(num){
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(" THURESDAY ");
break;
}
case 6:{
System.out.println(" FRIDAY ");
break;
}
case 7:{
System.out.println(" SATURDAY ");
break;
}
default :{
System.out.println("in valid number ");
}
}
}
}

___________________________________________________________________________________
_________________________________________________________________________________

3)WAP TO PRINT NUMBER OF THE DAY BY


READING THE NAME OF THE DAY ?

-----------------------------------------------------------------------------------
-------------------------------------------------------------------------------

Answer:======class Week1{
public static void main(String[] args){
String s="FRIDAY";
switch(s){
case "SUNDAY" :{
System.out.println(" 1 ");
break;
}
case "MONDAT" :{
System.out.println(" 2 ");
break;
}
case "TUESDAY" :{
System.out.println(" 3 ");
break;
}
case "WEDNESDAY" :{
System.out.println(" 4 ");
break;
}
case "THURESDAY" :{
System.out.println(" 5 ");
break;
}
case "FRIDAY" :{
System.out.println(" 6 ");
break;
}
case "SATURDAY" :{
System.out.println(" 7 ");
break;
}
default :{
System.out.println("in valid number ");
}
}
}
}

___________________________________________________________________________________
______________________________________________________
_________________________

4)WAP TO PRINT THE DAY IS


WORKING DAY OR NOT BY READING NUMBER OF THE DAY?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------

Answer:===class Week2{
public static void main(String[] args){
int num=7;
switch(num){
case 1:{
System.out.println(" SUNDAY IS NOTja WORKING
DAY ");
break;
}
case 2:{
System.out.println(" MONDAY IS WORKING DAY
");
break;
}
case 3:{
System.out.println(" TUESDAY IS WORKING DAY
");
break;
}
case 4:{
System.out.println(" WEDNESDAY IS WORKING DAY
");
break;
}
case 5:{
System.out.println(" THURESDAY IS WORKING DAY
");
break;
}
case 6:{
System.out.println(" FRIDAY IS WORKING DAY
");
break;
}
case 7:{
System.out.println(" SATURDAY IS WORKING DAY
");
break;
}
default :{
System.out.println("in valid number ");
}
}
}
}

___________________________________________________________________________________
________________________________________________________________________

5)WAP TO PRINT REMAING ALL DAYS BY


READING A DAY NUMBER ?

-----------------------------------------------------------------------------------
--------------------------------------------------------------------

Answer:===class Week3{
public static void main(String[] args){
int num=5;
switch(num){
case 1:{
System.out.print("S, ");

}
case 2:{
System.out.print(" M, ");

}
case 3:{
System.out.print(" T, ");

}
case 4:{
System.out.print(" W, ");

}
case 5:{
System.out.print(" T, ");

}
case 6:{
System.out.print(" F, ");

}
case 7:{
System.out.print(" S ");
break;
}
default :{
System.out.println("in valid number ");
}
}
}
}

___________________________________________________________________________________
_________________________________________________________________________
6)WAP TO PRINT NUMBER OF DAYS
IN A MONTH BY READING MONTH NUMBER ?

___________________________________________________________________________________
____________________________________________________________________________

Answer:====class DaysOfMounth{
public static void main(String[]
args){
int num=1;

switch(num){
case 1:{
System.out.println("Janavary
month 31 days");
break;
}
case 2:{
System.out.println("February
month 28 days");
break;
}
case 3:{
System.out.println("March
month 31 days");
break;
}
case 4:{
System.out.println("April
month 30 days");
break;
}
case 5:{
System.out.println("May
month 31 days");
break;
}
case 6:{
System.out.println("June
month 30 days");
break;
}
case 7:{
System.out.println("July
month 31 days");
break;
}
case 8:{
System.out.println("August
month 31 days");
break;
}
case 9:{
System.out.println("September
month 30 days");
break;
}
case 10:{
System.out.println("October
month 31 days");
break;
}
case 11:{
System.out.println("Navember
month 30 days");
break;
}
case 12:{
System.out.println("December
month 31 days");
break;
}
default :{
System.out.println("invalid
identifier ");
}
}
}
}

___________________________________________________________________________________
____________________________________________________________________________

7) WAP TO PRINT MONTH


NUMBER BY READING MOUNTH NAME ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-

Answer:===class Mounth{
public static void main(String[]
args){
String month="December";

switch(month){
case "Janavary":{
System.out.println("1 ");
break;
}
case "February":{
System.out.println("2");
break;
}
case "March":{
System.out.println("3");
break;
}
case "April":{
System.out.println("4");
break;
}
case "May":{
System.out.println("5");
break;
}
case "June":{
System.out.println("6");
break;
}
case "July":{
System.out.println("7");
break;
}
case "August":{
System.out.println("8");
break;
}
case "September":{
System.out.println("9");
break;
}
case "October":{
System.out.println("10");
break;
}
case "Navember":{
System.out.println("11");
break;
}
case "December":{
System.out.println("12");
break;
}
default :{
System.out.println("invalid
identifier ");
}
}
}
}

___________________________________________________________________________________
________________________________________________________________________________

8)WAP TO PRINT SEASONS


NAME BASED ON MONTH NAME?

-----------------------------------------------------------------------------------
------------------------------------------------------------------------------

Answer:=== class Scasons{


public static void main(String[] args){

String month="December";

switch(month){
case "Janavary":
case "February":{

System.out.println("WINTER");
break;
}
case "March":
case "April":
case "May":{
System.out.println("SUMMER");
break;
}
case "June":
case "July":
case "August":{
System.out.println("RAINY");
break;
}
case "September":
case "October":
case "Navember":{
System.out.println("SPRING");
break;
}
case "December":{
System.out.println("WINTER");
break;
}
default :{
System.out.println("invalid
identifier ");
}
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
_____

LOOPS
------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------

1)WAP TO PRINT 1 TO 10 NATURAL NUMBERS ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------

Answer:===class Natural{
public static void main(String[] args){
int n=1;
while(10>=n){
System.out.println(n++);
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
_________

2)WAP TO PRINT 1 TO N NATURAL NUMBERS ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------

Answer:===class NNatural{
public static void main(String[] args){
int n=1234;
for(int i=1;i<=n;i++){
System.out.println(i);
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
__________

3)WAP TO PRINT NATURAL B/W M


AND N ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----

Answer:=== class Reange{


public static void main(String[] args){
int m=100;
int n=200;
for(int i=m;i<=n;i++){
System.out.println(i);
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
______

4)WAP TO PRINT ALPHABETS


IN HORIZONTAL WAY ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------

Answer:=======class Alphabet{
public static void main(String[] args){
for(char ch='A';ch<='Z';ch++){
System.out.print(" "+ch+" ");
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
_____________

5)WAP TO PRINT LOWER


CASE ALPHABET AND UPPER CASE ALPHABET VERTICAL WAY ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------------

Answer:===class Alpha{
public static void main(String[] args){

for(int i=1;i<=26;i++){
System.out.println((char)(i+64)+" "+
(char)(i+96));
}

}
}

___________________________________________________________________________________
___________________________________________________________________________________
_________

6)4)WAP TO PRINT
ALPHABETS IN DESENDIG ORDER VERTICALY ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------

Answer:===class DescAlpha{
public static void main(String[] args){
for(int i=26;i>0;i--){
System.out.println((char)(i+64));
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
_____________

7)WAP TO PRINT UPPER CASE


ALPHABETS WITH NUMBERS IN VERTICSL WAY ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------------

Answer:====class AlphaNum{
public static void main(String[] args){
for(int i=1;i<=26;i++){
System.out.println((char)(i+64)+"
"+i);
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
__________

8)WAP TO PRINT THE


ALPHABET BY READING NUMBER ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------

Answer:===class Number11{
public static void main(String[] args){
int n=25;
for(int i=1;i<=26;i++){
if(n==i){
System.out.println((char)
(i+64));
}
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
_____________

9)WAP TO PRINT PRODUCT OF THE


NATURAL NUMBERS BETWEEN M AND N ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------

Answer:====class SumNum{
public static void main(String[]
args){
int m=10,n=20,sum=0;
for(int i=m;i<=n;i++){
sum=sum+i;
}
System.out.println(sum);
}

___________________________________________________________________________________
___________________________________________________________________________________
____

10)WAP TO EVEN NUMBERS


BETWEEN M AND N ?
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------

Answer:====class EvenNum{
public static void main(String[] args){
int m=10,n=30;
for(int i=m;i<=n;i++){
if(i%2==0)
System.out.println(i);
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
________

11)WAP TO PRINT ODD


NUMBERS BETWEEN M AND N ?

-----------------------------------------------------------------------------------
-------------------------------------------------------------------------------

Answer:======class OldNum{
public static void main(String[] args){
int m=10,n=30;
for(int i=m;i<=n;i++){
if(i%2==1)
System.out.println(i);
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
____
12)WAP TO PRINT
SUMMATION OF EVEN NUMBERS BETWEEN M AND N ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---

Answer:=====class EvenNumSum{
public static void
main(String[] args){
int
m=10,n=30,sum=0;
for(int
i=m;i<=n;i++){
if(i%2==0)

sum=sum+i;

System.out.println(sum);

___________________________________________________________________________________
___________________________________________________________________________________
_____________

13)WAP TO PRINT PRODUCT


OF ODD NUMBRS BETWEEN M AND N ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------

Answer:=====class OldNumSum{
public static void main(String[]
args){
int m=10,n=30,sum=1;
for(int i=m;i<=n;i++){
if(i%2==1)
sum=sum*i;
}
System.out.println(sum);
}
}

___________________________________________________________________________________
___________________________________________________________________________________
________
14)WAP TO PRINT SUMMATION OF
ODD NUMBERS BETWEEN M AND N ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------

Answer:====class OldNumSum{
public static void main(String[] args){
int m=10,n=30,sum=0;
for(int i=m;i<=n;i++){
if(i%2==1)
sum=sum+i;
}

System.out.println(sum);
}
}

___________________________________________________________________________________
___________________________________________________________________________________
_____________

15)WAP TO PRINT PRODUCT OF EVEN


NUMBRS BETWEEN M AND N ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------

Answer:===class OldNumpro{
public static void main(String[]
args){
int m=10,n=30,sum=1;
for(int i=m;i<=n;i++){
if(i%2==1)
sum=sum*i;
}
System.out.println(sum);
}
}

___________________________________________________________________________________
___________________________________________________________________________________
___________

16)WAP TO PRINT SUMMATION OF


THE NATURAL NUMBERS BETWEEN M AND N ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------
Answer:==== class Sumnatural{
public static void main(String[]
args){
int m=10,n=20,sum=1;
for(int i=m;i<=n;i++){

sum=sum+i;
}
System.out.println(sum);
}
}

___________________________________________________________________________________
___________________________________________________________________________________
_____________

17)WAP TO PRINT
MULTIPLICATION TABLE OF 2 ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------

Answer:======class Table2{
public static void main(String[] args){
for(int i=1;i<=10;i++){

System.out.println("2*"+i+"="+2*i);
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
_____________

18)WAP TO PRINT TABLE BY


READING USER INPUT ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------

Answer:=====import java.util.Scanner;
class UserInput{
public static void
main(String[] args){
Scanner sc=new
Scanner(System.in);

System.out.println("enter your nunber ");


int
num=sc.nextInt();
System.out.println(num+"..table");
for(int
i=1;i<=10;i++){

System.out.println(num+"*"+i+"="+(num*i));
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
______

20)WAP TO PRINT ENTERED


NUMBER IS DIVISBLE BY 7 OR NOT ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----

Answer:====class Dividible{
public static void main(String[]
args){

for(int i=10;i<=50;i++){
if(i%7==0){
System.out.println("number is
divisible by 7");
}
else{
System.out.println("number is
not divisible by 7");
}
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________

21)WAP TO COUNT THE


NUMBERS WHICCH ARE DIVISABLE BY 7 BETWEEN M AN N ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------

Answer:=====class DividibleBy7{
public static void
main(String[] args){
int co=0;
for(int i=10;i<=500;i++){
if(i%7==0){
co++;
}
}
System.out.println("count of 7
deviders.."+co);
}
}
}

___________________________________________________________________________________
________________________________________________________________________________

22)WAP TO PRINT
SUMMATION OF THE NUMBERS WHICH ARE DIVISABLE BY 5 BETWEEN M AND N ?

-----------------------------------------------------------------------------------
---------------------------------------------------------------------------------

Answer:====== class DividibleBy7{


public static void main(String[]
args){
int sum=0;
for(int i=10;i<=50;i++){
if(i%5==0){
sum=sum+i;
}

}
System.out.println(" sum of 5
deviders.."+sum);
}
}

___________________________________________________________________________________
___________________________________________________________________________________
______

23)WAP TO PRINT THE


QUOTIENT OF 85 DIVISIBLE BY 5 ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---

Answer:====class quoeitent{
public static void main(String[]
args){

int num=85;
if(num%5==0){
System.out.println(85/5);
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
_________

24)WAP TO PRINT THE QUOTIENT


OF THE NUMBER WITHOUT USING ANY DIVISION OPERATORS ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------------

Answer:=====class quoeitent1{
public static void
main(String[] args){

System.out.println(85/5);
}
}

___________________________________________________________________________________
___________________________________________________________________________________
_______________

25)WAP TO PRINT THE


REMAINDER OF THE NUMBER WITHOUT USING ANY DIVISION OPERATORS ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------

Answer:====class Reminder{
public static void
main(String[] args){

System.out.println(84%5);
}
}

___________________________________________________________________________________
___________________________________________________________________________________
_________________

IMP
QUESTIONS LOOPS
------
--------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------
1) WAP TO COUNT
DIGITS PRESENT IN A NUMBER ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------

Answer:====class CountOfNum{
public static void main(String[]
args){
int num=123456;
int count=0;
while(num>0){
int r=num%10;
count++;
num/=10;
}

System.out.println("count of digites in numbwr..."+count);

}
}

___________________________________________________________________________________
___________________________________________________________________________________
________________

2)WAP TO REVERSING
A NUMBER ?

_----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------

Answer:=====class Revers{
public static void
main(String[] args){
int num=123456,rev=0;
while(num>0){
int r=num%10;
rev=rev*10+r;
num/=10;
}

System.out.println("reverse of number is.."+rev);


}
}

___________________________________________________________________________________
___________________________________________________________________________________
___________________

2)WAP TO PRINT THE


DIGITS IN VETICALY ?
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------

Answer:=====class Vartical{
public static void main(String[]
args){
int num=1234556;
while(num>0){
int r=num%10;
System.out.println(r);
num/=10;
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
_______________

3)WAP TO PRINT THE DIGITS IN


HORIZONTALY ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------

Answer:======class Horizantal{
public static void
main(String[] args){
int num=1234556;
while(num>0){
int r=num%10;
System.out.print(" "+r+" ");
num/=10;
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
______________

4)WAP TO PRINT THE NUMBER FROM THE LAST


UNIT PLACE ?

-----------------------------------------------------------------------------------
---------------------------------------------------------------------------

Answer:===class Unit{
public static void main(String[] args){
int num=123456;
System.out.println(num%10+" last unites
place");
}
}

___________________________________________________________________________________
___________________________________________________________________________________
_____

2)WAP TO PRINT THE SUMMATIOM OF THE


NUMBER ?

_----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--

Answer:===class SunNum{
public static void main(String[]
args){
int num=123456,sum=0;
while(num>0){
int r=num%10;
sum=sum+r;
num/=10;
}
System.out.println(sum+"
addition of number");
}
}

___________________________________________________________________________________
___________________________________________________________________________________
__________

3)WAP TO CHECK WHETHER


GIVEN NUMBER IS PALINDROME OR NO ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----

Answer:=====class Phalandrom{
public static void
main(String[] args){
int
num=12343219,temp=num,sum=0;
while(num>0){
int r=num%10;
sum=sum*10+r;
num/=10;
}
if(temp==sum){

System.out.println("given number is phalondrom");


}
else{
System.out.println("given number is not phalandrom");

___________________________________________________________________________________
___________________________________________________________________________________
___

5)WAP TO CHECK WHETHER


SUMATION OF THE NUMBER IS EVEN OR ODD ?
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----

Answer:===class SumEven{
public static void
main(String[] args){
int
num=123456,sum=0;
while(num>0){
int r=num%10;
sum=sum+r;
num/=10;
}
if(sum%2==0)
{
System.out.println("sum
of digites is even "+sum);

}
else{
System.out.println("sum of
digites is ode "+sum);

}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
____

6)WAP TO CHECK WHETHER


PRODUCT OF THE NUMBER IS EVEN OR ODD ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------
Answer:======class ProOfDigs{
public static void
main(String[] args){
int
num=12345;
int
mul=1;

while(num>0){

int r=num%10;

mul=mul*r;

num/=10;

if(mul%2==0){

System.out.println("number product of individual digites is even


"+mul);

}
else{

System.out.println("number product of individual digites is even "+mul);

}
}

___________________________________________________________________________________
___________________________________________________________________________________
_______________

7)WAP TO PRINT NUMBERS BETWEEN M


AND N EXCEPT THE NUMBER WHICH HAS 7 IN IT ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------

Answer:==== class numberinit{


public static void
main(String[] args){
for(int
num=10;num<=50;num++){
int
i=num;

while(i>0){
int r=i%10;

if(r==7){

System.out.println("7 present in number is..."+num);

i=i/10;

___________________________________________________________________________________
___________________________________________________________________________________
______________________

8)WAP TO COUNT NUMBERS BETWEEN M


AND N THE NUMBER WHICH HAS 5 IN IT ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------

Answer:=====class numberinit{
public static void
main(String[] args){
int co=0;

for(int i=10;i<=50;i++){
if(digit(i)>0){
co++;
}
}

System.out.println( " 5number present in series count "+co);

}
public
static int digit(int i){

int co=0;

while(i>0){

int r=i%10;

if(r==5){
co++;

i=i/10;

return co;

___________________________________________________________________________________
___________________________________________________________________________________
_______________

9)WAP TO
COUNT HOW MANY 3 ARE PRESENT IN BETWEN M AND N ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------------

Answer:=====class numberinit{
public static void
main(String[] args){
int co=0;

for(int i=10;i<=50;i++){
if(digit(i)>0){
co++;
}
}

System.out.println( " 3number present in series count "+co);

}
public
static int digit(int i){

int co=0;

while(i>0){

int r=i%10;

if(r==3){
co++;

i=i/10;

return co;

___________________________________________________________________________________
___________________________________________________________________________________
____________________

10)WAP TO
PRINT HOW MANY NUMBERS HAVE 6 IN IT AND HOW MANY 6'S ARE PRESENT ?
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------------

Answer:====class num4{
public static void
main(String[] args){
int co=0,co1=0;

for(int i=10;i<=70;i++){
int
b=digit(i);

if(b>0){

co=co+b;
co1++;
}

System.out.println( " 6number present in series count "+co);

System.out.println( " 6number present in count "+co1);

}
public
static int digit(int i){

int co=0;
while(i>0){

int r=i%10;

if(r==6){

co++;

i=i/10;

return co;

}
___________________________________________________________________________________
___________________________________________________________________________________
_________________

STANDARD PROGRAMS :
-----------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------

1)WAP TO SWAP TWO


VARIABLES WITHOUT USING THIRD VARIABLE ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------

Answer:=======class Swap{
public static void main(String[]
args){
int a=12,b=23;
b=a+b;
a=b-a;
b=b-a;
System.out.println("a="+a+"\
n"+"b="+b);
}
}

___________________________________________________________________________________
___________________________________________________________________________________
__________________
2)WAP TO REVERSE A
NUMBER ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------

Answer:=====class reverse{
public static void main(String[] args){
int num=12345,sum=0;
while(num>0){
int r=num%10;
sum=sum*10+r;
num/=10;
}

System.out.println("reverse number is.."+sum);


}
}

___________________________________________________________________________________
___________________________________________________________________________________
__________________

3)WAP TO CHECK
WHETHER GIVEN NUMBER IS PALINDROME OR NOT ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------------

Answer:====class Palindrome{
public static void main(String[] args){
int num=1234321,sum=0;
int temp=num;
while(num>0){
int r=num%10;
sum=sum*10+r;
num/=10;
}
if(temp==sum){

System.out.println("given number is palindrome..."+sum);


}
else{

System.out.println("given number is palindrome..."+sum);


}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
______________
4)WAP TO
PRINT THE SUMMATION OF THE NUMBER ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------

Answer:=====class SumNum{
public static void
main(String[] args){
int num=123456,sum=0;
while(num>0){
int r=num%10;
sum=sum+r;
num/=10;
}

System.out.println("sumation of digites in number "+sum);


}
}

___________________________________________________________________________________
___________________________________________________________________________________
_________________

5)WAP
TO PRINT THE PRODUCT OF THE NUMBER ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------
Answer:==== class Pronum{
public static void
main(String[] args){
int
num=12345678,pro=1;
while(num>0){
int r=num
%10;
pro=pro*r;
num/=10;
}

System.out.println("product of digites of number "+pro);


}
}

___________________________________________________________________________________
___________________________________________________________________________________
_____________________

6)WAP
TO CHECK WHETHER GIVEN NUMBER IS A SPY NUMBER OR NOT ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------------

Answer:====class SpyNum{
public static void
main(String[] args){
int num=123456,temp=num;
int sum=0,pro=1;
while(num>0){
int r=num%10;
sum=sum+r;
pro=pro*1;
num/=10;
}
if(sum==pro){
System.out.println("given
number is spy number "+temp);
}
else{
System.out.println("given
number is not spy number "+temp);
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
__________________

7)WAP TO CHECK WHETHER


GIVEN NUMBER IS A PERFECT NUMBER OR NOT ?
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------

Answer:====class Prefect{
public static void
main(String[] args){
int num=6,sum=0;
for(int i=1;i<=num/2;i+
+){
if(num%i==0){
sum=sum+i;
}
}
if(num==sum){

System.out.println("given number is perfact number "+num);


}
else{

System.out.println("given number is not perfact number "+num);

}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
____________________

8)WAP TO CHECK WHETHER


GIVEN NUMBER IS A PERFECT SQUARE OR NOT ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------------

Answer:======class PerfactSqeare{
public static void
main(String[] args){
int num=2200,co=0;
for(int i=1;i<=num/2;i++){
int mul=1;
if(num%i==0){
mul=i*i;
if(num==mul){
co=1;
break;
}
}

if(co==1){

System.out.println("given number is perfact Sqeare number "+num);


}
else{

System.out.println("given number is not perfact Sqeare number "+num);


}
}

___________________________________________________________________________________
___________________________________________________________________________________
______________

9)WAP TO PRINT FACTORIAL


OF A NUMBER ?
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------------
Answer:=====class Factorial{
public static void
main(String[] args){
int num=5,fact=1;
for(int i=1;i<=num;i++){
fact=fact*i;
}
System.out.println(num+"
factorial is..."+fact);
}
}

___________________________________________________________________________________
___________________________________________________________________________________
________________

10)WAP TO CHECK
WHETHER GIVEN NUMBER IS STRONG NUMBER OR NOT ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------------
Answer:=====class StringNum{
public static void
main(String[] args){
int
num=145,temp=num,sum=0;
while(num>0){
int r=num%10;
int fact=1;
for(int i=1;i<=r;i++){
fact=fact*i;
}

sum=sum+fact;
num/=10;

if(temp==sum){

System.out.println("given number is String number.."+temp);


}
else{

System.out.println("given number is not String number.."+temp);


}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
____________________
11)WAP TO PRINT
THE X POWER N ?
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------------

Answer:====class XpawerN{
public static void
main(String[] args){
int x=5,n=5;
int p=1;
for(int
i=1;i<=n;i++){
p=x*p;
}

System.out.println(x+" power of "+n+ " "+p);

}
}

___________________________________________________________________________________
___________________________________________________________________________________
_____________________

12)WAP TO CHECK
WHETHER GIVEN NUMBER IS PRIME NUMBER OR NOT ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------------

Answer:=====class Prime{
public static void
main(String[] args){
int num=11,co=0;
for(int
i=1;i<=num;i++){
if(num%i==0)
{
co++;
}
}
if(co==2){

System.out.println("given number is a prime number "+num);

}
else{

System.out.println("given number is not a prime number "+num);

}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
___________________

13)WAP TO PRINT
PRIME NUMBER BY READING IT'S POSITION OF NUMBER ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------------------

Answer:=====class PrimePo{
public static void
main(String[] args){
int num=12345678;
while(num>0){
int r=num%10;
int co=0;
for(int
i=1;i<=r;i++){
if(r%i==0){
co++;

if(co==2){

System.out.println(" prime number is .."+r);

num/=10;

}
}

___________________________________________________________________________________
___________________________________________________________________________________
________________

14)WAP TO
PRINT SPY NUMBER BY READING IT'S POSITION OF NUMBER ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------------
Answer:======class SpyPo{
public static void
main(String[] args){
int
num=123456;

while(num>0){
int
s=0,p=1;
int
r=num%10;

if(r>0){

s=s+r;

p=p*r;

if(s==r){

System.out.println("Spy number is .."+r);

num/=10;

___________________________________________________________________________________
___________________________________________________________________________________
_________________

15)WAP
TO PRINT PERFECT NUMBER BY READING IT'S POSITION OF NUMBER ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------

Answer:=====class PerfactPo{
public static void
main(String[] args){
int num=1234567;
while(num>0){
int r=num%10;
int sum=0;
for(int
i=1;i<=r/2;i++){
if(r%i==0){
sum=sum+i;
}
if(sum==r){

System.out.println("perfact number is.."+r);


}
}
num/=10;
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
___________________

16)WAP TO
CHECK WHETHER GIVEN NUMBER IS ARMSTONG NUMBER OR NOT ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------------

Answer:=====class
ArmStrong{
public static void
main(String[] args){
int
num=153,temp=num,co=0,sum=0;
while(num>0)
{
int r=num
%10;
co++;

num/=10;

num=temp;

while(num>0){

int fact=1;

int r=num%10;
for(int
i=1;i<=co;i++){

fact=fact*r;

sum=sum+fact;
num/=10;

if(sum==temp){

System.out.println("given number is an aArmStrong number "+temp);

else{

System.out.println("given number is not an aArmStrong number "+temp);

}
}

___________________________________________________________________________________
___________________________________________________________________________________
____________

17)WAP TO PRINT
FIBINOCII SERIES ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------

Answer:====class Fibinosis{
public static void
main(String[] args){
int a=0,b=1,c=a+b;
System.out.println(a+"\
n"+b);
while(100>c){
System.out.println(c);
a=b;
b=c;
c=a+b;
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
________________

18)WAP TO PRINT
FIBINOCII SERIES BY READING THE VALUE ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------

Answer:====class FibiValue{
public static void main(String[]
args){
int
value=123,a=0,b=1,c=a+b;
while(100>c){
a=b;
b=c;
c=a+b;

if(value==c){

System.out.println("value present in fibinocii series");


}
}

}
}

___________________________________________________________________________________
___________________________________________________________________________________
_________________

19)WAP TO PRINT
SPY NUMBERS BEWEEN M AND N ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------------

Answer:=====class SpyNumBw{
public static void
main(String[] args){
for(int i=10;i<=1000;i++){
int num=i,s=0,p=1;
while(num>0){
int r=num%10;
s=s+r;
p=p*r;
num/=10;
}
if(s==p){
System.out.println("Spy
number is "+i);
}
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
__________________

20)WAP TO PRINT PERFECT


NUMBERS BETWEEN M AND N ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------
Answer:====class PerfNumBw{
public static void
main(String[] args){
for(int i=10;i<=1000;i++){
int num=i,sum=0;
for(int j=1;j<=num/2;j++){
if(num%j==0){
sum=sum+j;
}
}
if(sum==i){
System.out.println("perfact
number is .."+i);
}
}

}
}

___________________________________________________________________________________
___________________________________________________________________________________
___________________

21)WAP TO PRINT
PERFECT SQUARES BETWEEN M AND N ?

___________________________________________________________________________________
___________________________________________________________________________________
______________

Answer:====class PerfSqareNumBw{
public static void
main(String[] args){
for(int i=10;i<=1000;i++){
int num=i,pro=1;
for(int j=1;j<=num/2;j++){
if(num%j==0){
pro=j*j;
}
}

if(pro==i){

System.out.println("perfact number is .."+i);


}

}
}

___________________________________________________________________________________
___________________________________________________________________________________
________________
22)WAP TO PRINT STRONG NUMBERS
BETWEEN M AND N ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------

Answer:===class StrongNumBw{
public static void
main(String[] args){
for(int j=10;j<=100000;j++){
int
num=j,temp=num,sum=0;
while(num>0){
int r=num%10;
int fact=1;
for(int i=1;i<=r;i++){
fact=fact*i;
}

sum=sum+fact;
num/=10;

if(temp==sum){

System.out.println("given number is String number.."+j);


}

}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
_________________

23)WAP TO PRINT PRIME NUMBERS


BEETWEEN M AND N ?
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------------

Answer:======class PrimeNumBw{
public static void main
(String [] args){
for(int i=10;i<=100;i++){
int num=i,co=0;
for(int
j=1;j<=num;j++){
if(num%j==0){
co++;

}
}
if(co==2){

System.out.println("prime number is.."+i);

}
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
___________________

PATTERNS :
----------

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------

1) 1 1 1 1
1 1 @ 1
1 $ 1 1
1 1 1 1
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------

Answer:====class One{
public static void main(String[] args){
for(int i=1;i<=4;i++){
for(int j=1;j<=4;j++){
if(i==2 && j==3){
System.out.print(" "+"@"+" ");
}
else if(i==3 && j==2){
System.out.print(" "+"$"+" ");
}
else{
System.out.print(" "+"1"+" ");
}
}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
________________

2) A A % A
A A A A
A A A A
% A A A
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------------
Answer:====class Two{
public static void main(String[] args){
for(int i=1;i<=4;i++){
for(int j=1;j<=4;j++){
if((i==1 && j==3) || (i==4 && j==1)){
System.out.print(" "+"%"+" ");
}
else{
System.out.print(" "+"A"+" ");
}
}
System.out.println();
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
_______________
3)
0 0 0 0
0 0 0 0
^ 0 0 0
0 0 0 @

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------

Answer:====class Three{
public static void main(String[] args){
for(int i=1;i<=4;i++){
for(int j=1;j<=4;j++){
(i==3 && j==1){
System.out.print(" "+"^"+"
");
}
else if(i==4 && j==4){
System.out.print("
"+"@"+" ");
}
else{
System.out.print(" "+"0"+"
");
}
}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
______________

4)
a a a *
a a a a
a a $ a
a a a a

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------

Answer:====class four{
public static void main(String[] args){
for(int i=1;i<=4;i++){
for(int j=1;j<=4;j++){
if(i==1 && j==4){
System.out.print(" "+"*"+" ");
}
else if(i==3 && j==3){
System.out.print(" "+"$"+" ");
}
else{
System.out.print(" "+"a"+" ");
}
}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
_________________

5)

* * * a
* * 1 *
* @ * *
! * * *

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------

Answer:====class Five{
public static void main(String[] args){
for(int i=1;i<=4;i++){
for(int j=1;j<=4;j++){
if(i==1 && j==4){
System.out.print(" "+"a"+" ");
}
else if(i==2 && j==3){
System.out.print(" "+"1"+" ");
}
else if(i==3 && j==2){
System.out.print(" "+"@"+" ");
}
else if(i==4 && j==1){
System.out.print(" "+"!"+" ");
}
else{
System.out.print(" "+"*"+" ");
}
}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
__________________

6)
! ! ! !
A ! @ !
! ! ! !
! & ! #

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------
Answer:====class Six{
public static void main(String[] args){
for(int i=1;i<=4;i++){
for(int j=1;j<=4;j++){
if(i==2 && j==1){
System.out.print(" "+"A"+" ");
}
else if(i==2 && j==3){
System.out.print(" "+"1"+" ");
}
else if(i==4 && j==2){
System.out.print(" "+"&"+" ");
}
else if(i==4 && j==4){
System.out.print(" "+"#"+" ");
}
else{
System.out.print(" "+"!"+" ");
}
}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
_________________

7)
a * * *
* a * *
* * a *
* * * a
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------------

Answer:class Seven{
public static void main(String[] args){
for(int i=1;i<=4;i++){
for(int j=1;j<=4;j++){
if(i==j){
System.out.print(" "+"a"+" ");
}
else{
System.out.print(" "+"*"+" ");
}
}
System.out.println();
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
___________________

8)

* * * #
* * # *
* # * *
# * * *

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------------

Answer:=====class Eight{
public static void main(String[] args){
for(int i=1;i<=4;i++){
for(int j=1;j<=4;j++){
if(i+j==5){
System.out.print(" "+"#"+" ");
}
else{
System.out.print(" "+"*"+" ");
}
}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
____________________
9)
* * * *
* *
* *
* * * *

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------------

Answer:===class Nine{
public static void main(String[] args){
for(int i=1;i<=4;i++){
for(int j=1;j<=4;j++){
if(i==1 || i==4 || j==1 || j==3){
System.out.print(" "+"*"+" ");
}
else{
System.out.print(" "+" "+" ");
}
}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
_____________________

10) a * * * b
* c * d *
* * f * *
* G * h *
i * * * j

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------------

Answer:====class Ten{
public static void main(String[] args){
char ch='a';
for(int i=1;i<=5;i++){
for(int j=1;j<=5;j++){
if( i==j || i+j==6){
System.out.print(" "+ch+++"
");
}
else{
System.out.print(" "+"*"+"
");
}
}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
_____________________

11) 8 * * 7
* 6 5 *
* 4 3 *
2 * * 1
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------------

Answer:=======class leavean{
public static void main(String[] args){
int i1=8;
for(int i=1;i<=4;i++){
for(int j=1;j<=4;j++){
if( i==j || i+j==5){
System.out.print("
"+i1--+" ");
}
else{
System.out.print(" "+"*"+"
");
}
}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
_______________________

12) 5 4 3 2 1
5 4 3 2 1
5 4 3 2 1
5 4 3 2 1

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------------

Answer:=======class Twelve{
public static void main(String[] args){
for(int i=1;i<=4;i++){
for(int j=5;j>=1;j--){
System.out.print(" "+j+" ");
}
System.out.println();
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
____________________

13) e d c b a
e d c b a
e d c b a
e d c b a
e d c b a

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------

Answer:=====class Thirteen{
public static void main(String[] args){
for(int i=1;i<=5;i++){
for(char c='e';c>='a';c--){
System.out.print(" "+c+" ");
}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
__________________

14) 1 2 3 4
5 6 7 8
9 1 2 3
4 5 6 7

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------------

Answer:======class fourteen{
public static void main(String[] args){
int num=1;
for(int i=1;i<=4;i++){
for(int j=1;j<=4;j++){
System.out.print(" "+num+" ");
num=num%9+1;
}
System.out.println();
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
_____________________

15)
i h g f
e d c b
a i h g
f e d c
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------------

Answer:=====class fiveteen{
public static void main(String[] args){
char c='i';

for(int i=1;i<=4;i++){
for(int j=1;j<=4;j++){
System.out.print(" "+c--+" ");
if(c==96){
c='i';
}
}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
________________________

16) 1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------------

Answer:====class sixteen{
public static void main(String[] args){
for(int i=1;i<=4;i++){
for(int j=1;j<=4;j++){
System.out.print(" "+j+" ");
}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
_______________
17) A B C D
E F G D
I J K L
M N O p

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------------

Answer:====class Seventeen{
public static void main(String[] args){
char c='A';
for(int i=1;i<=4;i++){
for(int j=1;j<=4;j++){
System.out.print(" "+c+++" ");
}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
______________________

18) A B C D
1 2 3 4
A B C D
1 2 3 4

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------------------

Answer:=====class Eighteen{
public static void main(String[] args){
for(int i=1;i<=4;i++){
int a=1;
for(char c='A';c<='D';c++){
if(i%2==1){
System.out.print(" "+c+" ");
}
else{
System.out.print(" "+a+++" ");
}
}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
__________________
19) 1 2 3 4
a b c d
1 2 3 4
e f g h

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------------

Answer:=====class nineteen{
public static void main(String[] args){
char a='a';
for(int i=1;i<=4;i++){
for(int j=1;j<=4;j++){
if(i%2==1){
System.out.print(" "+j+" ");
}
else{
System.out.print(" "+a+++" ");
}
}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
___________________

20) A 1 B 2
C 3 D 4
E 5 F 6
G 7 H 8

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------------

Answer:=====class Twenty{
public static void main(String[] args){
int a=1;
char c='A';
for(int i=1;i<=4;i++){
for(int j=1;j<=4;j++){

if(j%2==1){
System.out.print(" "+c++
+" ");
}
else{
System.out.print(" "+a+++"
");
}
}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
___________________

21) 1 a 1 a
1 a 1 a
1 a 1 a
1 a 1 a

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------

Answer:=====class TwentyOne{
public static void main(String[] args){

for(int i=1;i<=4;i++){
for(int j=1;j<=4;j++){

if(j%2==1){
System.out.print(" "+"1"+" ");
}
else{
System.out.print(" "+"a"+" ");
}
}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
_____________

22)
a 1 + 2 b
c 3 + 4 d
e 5 + 6 f
g 7 + 8 h

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------

Answer:=====class TwentyTwo{
public static void main(String[] args){
int a=1;
char c='a';
for(int i=1;i<=4;i++){
for(int j=1;j<=5;j++){
if( j==3){
System.out.print(" "+"+"+" ");
}

else if(j%2==1){
System.out.print(" "+c+++" ");
}

else{
System.out.print(" "+a+++" ");
}
}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
____________

23)
a 1 b 2 c
d 3 e 4 f
g 5 h 6 i
j 7 k 8 l
i 9 + 10 j
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------

Answer:=====class TwentyThree{
public static void main(String[] args){
int a=1;
char c='a';
for(int i=1;i<=5;i++){
for(int j=1;j<=5;j++){
if(i==5 && j==3){
System.out.print(" "+"+"+"
");
}

else if(j%2==1){
System.out.print(" "+c+++" ");
if(c=='m'){
c='i';
}
}

else{
System.out.print(" "+a+++"
");
}
}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
________________

24) 1 2 3 4 5
a b c d e
+ + + + +
a b c d e
1 2 3 4 5

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------

Answer:========class TwentyFore{
public static void main(String[] args){
for(int i=1;i<=5;i++){
char c='a';
for(int j=1;j<=5;j++){
if(i%2==0){
System.out.print(" "+c+++"
");
}
else if(i==3){
System.out.print(" "+"+"+"
");
}
else{
System.out.print(" "+j+" ");
}
}
System.out.println();
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
_____________

25)
1 z 2 y
3 x 4 w
5 v 6 u
7 t 8 s
9 r 1 q
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------

Answer:====class TwentyFive{
public static void main(String[] args){
char c='z';
int a=1;
for(int i=1;i<=5;i++){
for(int j=1;j<=4;j++){
if(j%2==1){
System.out.print(" "+a+++" ");
if(a==10){
a=1;
}
}
else{
System.out.print(" "+c--+" ");
}
}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
______________

26) 1 a 4 d
7 g 10 j
13 m 16 p
19 s 22 v

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------
Answer:======class TwentySix{
public static void main(String[] args){
char c='a';
int a=1;
for(int i=1;i<=4;i++){
for(int j=1;j<=4;j++){
if(j%2==1){
System.out.print(" "+a+" ");
a=a+3;
}
else{

System.out.print(" "+c+"
");
c=(char)(c+3);
}
}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
_______________

27)

1 A # B 2
3 C # D 4
# # # # #
5 E # F 6
7 G # H 8

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------

Answer:=====class TwentySeven{
public static void main(String[] args){
int a=1;
char A='A';
for(int i=1;i<=5;i++){
for(int j=1;j<=5;j++){
if(i==3 || j==3){
System.out.print(" "+"#"+"
");
}
else if(j%2==0){
System.out.print(" "+A+++"
");
}
else{
System.out.print(" "+a+++"
");
}
}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
______________

28)
*
* *
* * *
* * * *
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------

Answer:======class twentyEight{
public static void main(String[] args){
int a=0;
for(int i=1;i<=4;i++){
a++;
for(int j=1;j<=a;j++){
System.out.print(" "+"*"+" ");
}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
_______________

29) * * * *
* * *
* *
*

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------------

Answer:=====class TwentyNine{
public static void main(String[] args){
int space=-1;
int star=5;
for(int i=1;i<=4;i++){
space++;
star--;
for(int j=1;j<=space;j++){
System.out.print(" "+" "+" ");
}
for(int j=1;j<=star;j++){
System.out.print(" "+"*"+" ");
}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
______________

30)
* * * *
* * *
* *
*

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------------

Answer:=======class threty{
public static void main(String[] args){
int a=5;
for(int i=1;i<=4;i++){
a--;
for(int j=1;j<=a;j++){
System.out.print(" "+"*"+" ");
}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
__________
31)
*
* *
* * *
* * * *

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------

Answer:====class Thretyone{
public static void main(String[] args){
int space=-1;
int star=5;
for(int i=1;i<=4;i++){
space++;
star--;
for(int j=1;j<=space;j++){
System.out.print(" "+" "+" ");
}
for(int j=1;j<=star;j++){
System.out.print(" "+"*"+" ");
}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
__________

32) a
b c
d e f
g h i j

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------

Answer:======class thretyTwo{
public static void main(String[] args){
int a=0;
char A='a';
for(int i=1;i<=4;i++){
a++;
for(int j=1;j<=a;j++){
System.out.print(" "+A+++" ");
}
System.out.println();
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
_________

33)
1
2 3
4 5 6
7 8 9 10

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------------

Answer:=====class ThretyThree{
public static void main(String[] args){
int a=0;
int A=1;
for(int i=1;i<=4;i++){
a++;
for(int j=1;j<=a;j++){
System.out.print(" "+A+++" ");
}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
____________

34)

a
1 2
b c d
3 4 5 6

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------

Answer:=======class ThretyFour{
public static void main(String[] args){
int a=0;
int A=1;
char ch='a';
for(int i=1;i<=4;i++){
a++;
for(int j=1;j<=a;j++){
if(i%2==0){
System.out.print(" "+ch+++" ");
}
else{
System.out.print(" "+A+++" ");
}

}
System.out.println();
}
}
}

___________________________________________________________________________________
____________________________________________________________________________

35)
1
a b
1 2 3
a b c d

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------

Answer:=====class ThretyFive{
public static void main(String[] args){
int a=0;
for(int i=1;i<=4;i++){
int A=1;
char ch='a';
a++;
for(int j=1;j<=a;j++){
if(i%2==1){
System.out.print(" "+A+++" ");
}
else{
System.out.print(" "+ch+++" ");
}

}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
_____________

36)
1
2 a
3 b 4
5 c 6 d
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------------

Answer:=====class ThretySix{
public static void main(String[] args){
int a=0;
int A=1;
char ch='a';
for(int i=1;i<=4;i++){
a++;
for(int j=1;j<=a;j++){
if(j%2==1){
System.out.print(" "+A+++" ");
}
else{
System.out.print(" "+ch+++" ");
}

}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
____________

37)

e d c b a
e d c b
e d c
e d
e

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------

Answer:=======class ThretySeven{
public static void main(String[] args){
int space=0;
int star=6;
for(int i=1;i<=5;i++){
space++;
star--;
char ch='e';
for(int j=1;j<=space;j++){
System.out.print(" "+" "+" ");
}
for(int j=1;j<=star;j++){
System.out.print(" "+ch--+" ");
}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
____________

38)
5 4 3 2 1
a b c d
5 4 3
a b
5

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------

Answer:=====class thretyeight{
public static void main(String[] args){
int a=6;
for(int i=1;i<=5;i++){
a--;
int v=5;
char c='a';
for(int j=1;j<=a;j++){
if(i%2==1){
System.out.print(" "+v--+" ");
}
else{
System.out.print(" "+c+++" ");
}
}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
_____________

39) e
e d
e d c
e d c b
e d c b a
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------------

Answer:=====class ThretyNine{
public static void main(String[] args){
int star=0;
for(int i=1;i<=5;i++){
star++;
char ch='e';
for(int j=1;j<=star;j++){
System.out.print(" "+ch--+" ");
}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
___________

60) 1
3 2
6 5 4
10 9 8 7

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------

Answer:=====

___________________________________________________________________________________
___________________________________________________________________________________
_____________

40)
* *
* * * *
* * * * * *
* * * * * * * *

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----

Answer:=====class Forty{
public static void main(String[] args){
int star=0;
int space=8;
for(int i=1;i<=4;i++){
star++;
space-=2;
for(int j=1;j<=star;j++){
System.out.print(" * ");
}
for(int j=1;j<=space;j++){
System.out.print(" ");
}
for(int j=1;j<=star;j++){
System.out.print(" * ");
}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
______________

41)

* *
* * * *
* * * * * *
* * * * * * * *

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------
Answer:=====class FortyOne{
public static void main(String[] args){
int star=0;
int space=4;
for(int i=1;i<=4;i++){
star++;
space--;
for(int j=1;j<=star;j++){
System.out.print(" * ");
}
for(int j=1;j<=space;j++){
System.out.print(" ");
}
for(int j=1;j<=star;j++){
System.out.print(" * ");
}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
_______

42)

* * * * *
* * * * *
* * * * *
* * * * *

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------

Answer:====class FortyTwo{
public static void main(String[] args){
int star=5;
int star1=0;
int space=-1;
for(int i=1;i<=4;i++){
star--;
star1++;
space++;
for(int j=1;j<=star;j++){
System.out.print(" * ");
}
for(int j=1;j<=space;j++){
System.out.print(" ");
}
for(int j=1;j<=star1;j+
+){
System.out.print(" * ");
}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
________

43)
* * * * *
* * * * *
* * * * *
* * * * *

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------
Answer:====class FortyThree{
public static void main(String[] args){
int star=0;
int star1=5;
int space=4;
for(int i=1;i<=4;i++){
star++;
star1--;
space--;
for(int j=1;j<=star;j++){
System.out.print(" * ");
}
for(int j=1;j<=space;j++){
System.out.print(" ");
}
for(int j=1;j<=star1;j++){
System.out.print(" * ");
}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
_______

44)
*
* * *
* * * * *
* * * * * * *
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------------

Answer:======class FortyFour{
public static void main(String[] args){
int star=-1;
int space=4;
for(int i=1;i<=4;i++){
star+=2;
space--;
for(int j=1;j<=space;j++){
System.out.print(" ");
}
for(int j=1;j<=star;j++){
System.out.print(" * ");
}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
____________

45)
* * * * * * *
* * * * *
* * *
*

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------

Answer:======class FortyFive{
public static void main(String[] args){
int star=9;
int space=-1;
for(int i=1;i<=4;i++){
star-=2;
space++;
for(int j=1;j<=space;j++){
System.out.print(" ");
}
for(int j=1;j<=star;j++){
System.out.print(" * ");
}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
________________

46)

*
* * *
* * * * *
* * *
*

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------

Answer:=======class FortySix{
public static void main(String[] args){
int star=-1;
int space=3;
for(int i=1;i<=5;i++){
if(i<=3){
star+=2;
space--;
}
else{
star-=2;
space++;
}

for(int j=1;j<=space;j++){
System.out.print(" ");
}
for(int j=1;j<=star;j++){
System.out.print(" * ");
}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
________________

47)
A
A B C
A B C D E
A B C
A

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------

Answerclass FortySeven{
public static void main(String[] args){
int star=-1;
int space=3;
for(int i=1;i<=5;i++){
if(i<=3){
star+=2;
space--;
}
else{
star-=2;
space++;
}
char ch='A';

for(int j=1;j<=space;j++){
System.out.print(" ");
}
for(int j=1;j<=star;j++){
System.out.print(" "+ch+++" ");
}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
________

48)

1
2 2 2
3 3 3 3 3
4 4 4 4 4 4 4
3 3 3 3 3
2 2 2
1
-----------------------------------------------------------------------------------
----------------------------------------------------------------------------------

Answer:=========class FortyEight{
public static void main(String[] args){
int star=-1;
int space=4;
int a=0;
for(int i=1;i<=7;i++){
if(i<=4){
star+=2;
space--;
a++;
}
else{
star-=2;
space++;
a--;
}

for(int j=1;j<=space;j++){
System.out.print(" ");
}
for(int j=1;j<=star;j++){
System.out.print(" "+a+" ");
}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
_______

49)

A
A B A
A B C B A
A B C D C B A

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------

Answer:=====class FortyNine{
public static void main(String[] args){
int star=-1;
int space=4;
for(int i=1;i<=4;i++){
star+=2;
space--;
char ch='A';
for(int j=1;j<=space;j++){
System.out.print(" ");
}
for(int j=1;j<=star;j++){
if(j<=star/2){
System.out.print(" "+ch+++" ");
}
else{
System.out.print(" "+ch--+" ");
}

}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
_____________

50)

1 2 3 4 3 2 1
1 2 3 2 1
2 1 2
1
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------------

Answer:=====class Fivety{
public static void main(String[] args){
int star=9;
int space=-1;
for(int i=1;i<=4;i++){
star-=2;
space++;
int ch=1;
for(int j=1;j<=space;j++){
System.out.print(" ");
}
for(int j=1;j<=star;j++){
if(j<=star/2){
System.out.print(" "+ch+++" ");
}
else{
System.out.print(" "+ch--+" ");
}

}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
________________ 51)
A
A B A
A B C B A
A B C D C B A
A B C B A
A B A
A

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------

Answer:======class FivetyOne{
public static void main(String[] args){
int star=-1;
int space=4;
for(int i=1;i<=7;i++){
if(i<=4){
star+=2;
space--;
}
else{
star-=2;
space++;
}

char ch='A';

for(int j=1;j<=space;j++){
System.out.print(" ");
}
for(int j=1;j<=star;j++){
if(j<=star/2){
System.out.print(" "+ch+++" ");
}
else{
System.out.print(" "+ch--+" ");
}

}
System.out.println();
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
_______________

ARRAY

------

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------

1)WAP TO CREATE AN ARRAY SIZE OF 5 AND STORE THE VALUE FROM


THE USER?
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------

Ans:=======
import java.util.Scanner;
class P1 {
public static void main(String[] args) {
Scanner sc=new
Scanner(System.in);
System.out.println("enter your
number....!");
int n=sc.nextInt();
int a[]=new int[n];
System.out.println("enter array
elements>.....!");
for(int i=0;i<a.length;i++){
a[i]=sc.nextInt();
}
for(int i:a){
System.out.println("array
elements is..."+i);
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
____________________

2)WAP TO PRINT EVEN INDEX OF FROM AN ELEMENTS ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------------

Answer:======
import java.util.Scanner;
class ArrayIndexPos {
public static void main(String[]
args)
{
Scanner sc=new
Scanner(System.in);
System.out.println("enter
length of array..");
int n=sc.nextInt();
int a[]=new int[n];

System.out.println("enter elements in array...");


for(int
i=0;i<a.length;i++){
a[i]=sc.nextInt();
}
for(int
i=0;i<a.length;i++){
if(i%2==0){
System.out.println("even
indexe position of array elemenet is .."+a[i]);
}
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
______________

3)WAP TO PRINT ODD INDEX


OF ELEMENT ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------
Answer:======= import java.util.Scanner;
class ArrayIndexPosOld {
public static void main(String[]
args)
{
Scanner sc=new Scanner(System.in);
System.out.println("enter length of
array..");
int n=sc.nextInt();
int a[]=new int[n];
System.out.println("enter elements
in array...");
for(int
i=0;i<a.length;i++){
a[i]=sc.nextInt();
}
for(int i=0;i<a.length;i++){
if(i%2==1){
System.out.println("Old
indexe position of array elemenet is .."+a[i]);
}
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
__________

4)WAP TO FIND SUM


OF ALL GIVEN ELEMENTS FROM AN ARRAY ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------

Answer:=======
import
java.util.Scanner;
class ArraySumElements
{
public static void
main(String[] args){
Scanner sc=new
Scanner(System.in);

System.out.println("enter length of array");


int
n=sc.nextInt();
int a[]=new
int[n];

System.out.println("enter elemenets of an array");


for(int
i=0;i<a.length;i++){

a[i]=sc.nextInt();
}
int sum=0;
for(int
i=0;i<a.length;i++){
sum=sum+a[i];
}
System.out.println("Sum
of all elements of an array.."+sum);
}
}

___________________________________________________________________________________
___________________________________________________________________________________
____________________

5)WAP TO FIND
AVRAGE ELEMENT FROM AN ARRAY ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------

Answer:=====

import java.util.Scanner;
class ArrayAvarage {
public static void
main(String[] args){
Scanner sc=new
Scanner(System.in);

System.out.println("enter length of array...");


int n=sc.nextInt();

System.out.println("enter array elements...");


int a[]=new int[n];
for(int
i=0;i<a.length;i++){
a[i]=sc.nextInt();
}
int sum =0;
for(int
i=0;i<a.length;i++){

sum=sum+a[i];
}
System.out.println("
avareage of array elements "+sum/n);
}
}

___________________________________________________________________________________
___________________________________________________________________________________
_________________

6)WAP TO FIND SUMMATION


OF EVEN INDEX ELEMENTS FROM AN ARRAY?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------

Answer:======

import java.util.Scanner;
class SumEven {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("enter lengrh of
array !");
int n=sc.nextInt();
System.out.println("enter array
elements ..");
int a[]=new int[n];

for(int i=0;i<a.length;i++){
a[i]=sc.nextInt();
}
int sum=0;
for(int i=0;i<a.length;i++){
if(i%2==0){
sum=sum+a[i];
}
}
System.out.println("Sum of
even elements in an arrar....!="+sum);

}
}

___________________________________________________________________________________
___________________________________________________________________________________
____________________
7)WAP TO FIND
SUMMATION OF ODD INDEX ELEMENTS FROM AN ARRAY ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------------------

Answer:========import
java.util.Scanner;
class SumOdd {
public static void main(String[]
args){
Scanner sc=new Scanner(System.in);
System.out.println("enter lengrh of
array !");
int n=sc.nextInt();
System.out.println("enter array
elements ..");
int a[]=new int[n];

for(int i=0;i<a.length;i++){
a[i]=sc.nextInt();
}
int sum=0;
for(int i=0;i<a.length;i++){
if(i%2==1){
sum=sum+a[i];
}
}
System.out.println("Sum of even
elements in an arrar....!="+sum);

}
}

___________________________________________________________________________________
___________________________________________________________________________________
___________

9)WAP TO PRINT FIRST HALF OF


THE ARRAY ELEMENTS ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------
Answer:======import
java.util.Scanner;
class HalfArray {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("enter lengrh of array !");
int n=sc.nextInt();
System.out.println("enter array elements ..");
int a[]=new int[n];

for(int i=0;i<a.length;i++){
a[i]=sc.nextInt();
}
int sum=0;
for(int i=0;i<a.length;i++){
if(a.length/2>i){
sum=sum+a[i];
}
}
System.out.println("Sum of even elements in an arrar....!="+sum);

}
}

___________________________________________________________________________________
___________________________________________________________________________________
_________________

10)WAP TO
PRINT SECOND HALF OF THE ARRAY ELEMENTS ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------------

Answer:=======import java.util.Scanner;
class ScoendArray {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("enter lengrh of array !");
int n=sc.nextInt();
System.out.println("enter array elements ..");
int a[]=new int[n];

for(int i=0;i<a.length;i++){
a[i]=sc.nextInt();
}
int sum=0;
for(int i=0;i<a.length;i++){
if(a.length/2<i){
sum=sum+a[i];
}
}
System.out.println("Sum of even elements in an arrar....!="+sum);

}
}

___________________________________________________________________________________
___________________________________________________________________________________
__________________

11)WAP TO FIND AVAREGE


VALUE OF EVEN INDEX FROM AN ARRAY ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------

Answer:========import java.util.Scanner;
class AvgSumEvenInd {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("enter lengrh of array !");
int n=sc.nextInt();
System.out.println("enter array elements ..");
int a[]=new int[n];

for(int i=0;i<a.length;i++){
a[i]=sc.nextInt();
}
int sum=0,co=0;
for(int i=0;i<a.length;i++){
if(i%2==0){
sum=sum+a[i];
co++;
}
}
System.out.println("Avareage sum of even position....!="+sum/co);

}
}

___________________________________________________________________________________
___________________________________________________________________________________
_________________
12)WAP TO FIND AVAREGE VALUE OF ODD
INDEX FROM AN ARRAY ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------

Answer:========import
java.util.Scanner;
class AvgSumOddInd {
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("enter lengrh of array !");
int n=sc.nextInt();
System.out.println("enter array elements ..");
int a[]=new int[n];

for(int i=0;i<a.length;i++){
a[i]=sc.nextInt();
}
int sum=0,co=0;
for(int i=0;i<a.length;i++){
if(i%2==1){
sum=sum+a[i];
co++;
}
}
System.out.println("Avareage sum of old position....!="+sum/co);

}
}

___________________________________________________________________________________
___________________________________________________________________________________
______________________

13)WAP TO FIND AVAREGE


VALUE OF FIRST HALF FROM AN ARRAY ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------------
Answer:====import java.util.Scanner;
class FitsrHalfAvg {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("enter index length");
int n=sc.nextInt();
System.out.println("enter array elements");
int a[]=new int[n];
for(int i=0;i<a.length;i++){
a[i]=sc.nextInt();
}
int sum=0,co=0;
for(int i=0;i<a.length;i++){

if(a.length/2>i){
sum=sum+a[i];
co++;
}
}
System.out.println("sum of first half index numbers..."+
(sum/co));

System.out.println("Hello World!");
}
}

___________________________________________________________________________________
___________________________________________________________________________________
______________

14)WAP TO FIND AVAREGE VALUE OF SECOND


HALF FROM AN ARRAY ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------

Answer:=======import java.util.Scanner;
class SecondHalfAvg {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("enter index length");
int n=sc.nextInt();
System.out.println("enter array elements");
int a[]=new int[n];
for(int i=0;i<a.length;i++){
a[i]=sc.nextInt();
}
int sum=0,co=0;
for(int i=0;i<a.length;i++){

if(a.length/2<i){
sum=sum+a[i];
co++;
}
}
System.out.println("sum of Second half index numbers..."+
(sum/co));

System.out.println("Hello World!");
}
}

___________________________________________________________________________________
___________________________________________________________________________________
___________________

15)WAP TO FIND MAX


ELEMENT FROM AN ARRAY ?

_----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------

Answer:=====import java.util.Scanner;
class MaxmunEle {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("enter index length");
int n=sc.nextInt();
System.out.println("enter array elements");
int a[]=new int[n];
for(int i=0;i<a.length;i++){
a[i]=sc.nextInt();
}
int temp=0;
for(int i=1;i<a.length;i++){

if(a[i]>a[i-1]){
temp=a[i];
}
}
System.out.println("maxmum element in array..."+temp);
System.out.println("Hello World!");
}
}

___________________________________________________________________________________
___________________________________________________________________________________
____________________

16)WAP TO FIND MIX


ELEMENT FROM AN ARRAY ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------

Answer:=====import java.util.Scanner;
class MinimumEle {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("enter index length");
int n=sc.nextInt();
System.out.println("enter array elements");
int a[]=new int[n];
for(int i=0;i<a.length;i++){
a[i]=sc.nextInt();
}
int temp=0;
for(int i=1;i<a.length;i++){

if(a[i]<a[i-1]){
temp=a[i];
}
}
System.out.println("maxmum element in array..."+temp);

System.out.println("Hello World!");
}
}

___________________________________________________________________________________
___________________________________________________________________________________
_________________

17)WAP TO READ EVEN INDEXED


ELEMENTS OF AN ARRAY ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------

Answer:=======import java.util.Scanner;
class EvenIndexEle {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("enter index length");
int n=sc.nextInt();
System.out.println("enter array elements");
int a[]=new int[n];
for(int i=0;i<a.length;i++){
a[i]=sc.nextInt();
}

for(int i=0;i<a.length;i++){

if(a[i]%2==0){
System.out.println("even index elements...."+a[i]);

}
}

}
}

___________________________________________________________________________________
___________________________________________________________________________________
_________________

18)WAP TO PRINT ELEMENTS IN


ASCENDING ORDER ?

___________________________________________________________________________________
___________________________________________________________________________________
_________________

Answer:=========import java.util.Scanner;
class Asending{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("enter your length of arragy");
int n=sc.nextInt();
System.out.println("enter ayyar elements");
int a[]=new int[n];
for(int i=0;i<a.length;i++){
a[i]=sc.nextInt();

}
int temp=0;
for(int i=0;i<a.length-1;i++){
for(int j=1;j<a.length-i;j++){
if(a[j-1]>a[j]){
temp=a[j-1];
a[j-1]=a[j];
a[j]=temp;
}
}
}
for(int i:a){
System.out.println(i);
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
__________________

19)WAP TO PRINT ELEMENTS IN


DESCENDING ORDER ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------------------

Answer:=====import java.util.Scanner;
class descnding{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
System.out.println("enter your length of arragy");
int n=sc.nextInt();
System.out.println("enter ayyar elements");
int a[]=new int[n];
for(int i=0;i<a.length;i++){
a[i]=sc.nextInt();

}
int temp=0;
for(int i=0;i<a.length-1;i++){
for(int j=1;j<a.length-i;j++){
if(a[j-1]<a[j]){
temp=a[j-1];
a[j-1]=a[j];
a[j]=temp;
}
}
}
for(int i:a){
System.out.print(" "+i+" ");
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
__________________

20)WAP TO PRINT AVRAGE ELEMENT FROM AN ARRAY ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------

Answer:=======class AvageEle {
public static void main(String[] args) {
int a[]={10,20,30,40,502};
int sum=0,co=0,avg;
for(int i=0;i<a.length;i++){
sum=sum+a[i];
}
avg=sum/(a.length);
for(int i=0;i<a.length;i++){
if(avg==a[i]){
co++;
}
}
if(co==0){
System.out.println("avarage element is not found "+avg);
}
else{
System.out.println("avarage element is found..."+avg);
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
_________________

21)WAP TO PRINT 2ND HIGHEST ELEMENT


OF AN ARRAY ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------------

Answer:======class LargestEle {
public static void main(String[] args) {
int a[]={9,25,61,3,6,5};
int len=a.length;
int temp=0;
for(int i=0;i<len-1;i++){
for(int j=1;j<len-i;j++){
if(a[j-1]>a[j]){
temp=a[j-1];
a[j-1]=a[j];
a[j]=temp;
}
}
}
System.out.println("second largest element of Array..."+a[len-
2]);

}
}

___________________________________________________________________________________
___________________________________________________________________________________
________________

22)WAP TO PRINT 2ND LOWEST ELEMENT OF AN


ARRAY ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------------

Answer:=======class SmallestEle {
public static void main(String[] args) {
int a[]={9,25,61,3,6,5};
int len=a.length;
int temp=0;
for(int i=0;i<len-1;i++){
for(int j=1;j<len-i;j++){
if(a[j-1]>a[j]){
temp=a[j-1];
a[j-1]=a[j];
a[j]=temp;
}
}
}
System.out.println("second largest element of Array..."+a[1]);

}
}
___________________________________________________________________________________
___________________________________________________________________________________
__________________

23)WAP TO CHECK GIVEN VALUE


IS PRESENT IN THE ARRAY OR NOT ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------

Answer:====== class Eleper {


public static void main(String[] args){
int a[]={10,20,30,60,40,50};
int ele=21;
int co=0;
for(int i=0;i<a.length;i++){
if(a[i]==ele){
co++;
}
}
if(co==0){
System.out.println("given elemenet is not
fount..."+ele);
}
else{
System.out.println("given element is
found..."+ele);
}

}
}

___________________________________________________________________________________
___________________________________________________________________________________
______________

24)WAP TO FIND MAX ELEMENT


OF EVEN INDEX FROM AN ARRAY ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------

Answer:=====
class MaxEvenEle{
public static void main(String[] args)
{
int a[]={10,20,30,60,50,40,90};
int max=0,ele=a[0];
for(int i=0;i<a.length;i++){
if(i%2==0){
max=a[i];
if(ele<max){
ele=max;
}
}
}
System.out.println("even position of max element is.."+ele);
}
}

___________________________________________________________________________________
___________________________________________________________________________________
_________________

25)WAP TO FIND MAX


ELEMENT OF ODD INDEX FROM AN ARRAY ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------

Answer:======= class MaxOddEle{


public static void main(String[] args)
{
int a[]={10,20,30,60,50,40,90};
int max=0,ele=a[0];
for(int i=0;i<a.length;i++){
if(i%2==1){
max=a[i];
if(ele<max){
ele=max;
}
}
}
System.out.println("Odd position of max element is.."+ele);
}
}

___________________________________________________________________________________
___________________________________________________________________________________
__________________

26)WAP TO FIND MAX


ELEMENT OF FIRST HALF FROM AN ARRAY ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------

Answer:======class MaxFirstHalfArrayEle{
public static void main(String[] args)
{
int a[]={10,20,30,60,50,40,90};
int max=0,ele=a[0];
for(int i=0;i<a.length;i++){
if(a.length/2>i){
max=a[i];
if(ele<max){
ele=max;
}
}
}
System.out.println("first half array position of max element
is.."+ele);
}
}

___________________________________________________________________________________
___________________________________________________________________________________
_________________

27)WAP TO FIND MAX ELEMENT OF


SECOND HALF FROM AN ARRAY ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------

Answer:=====
class MaxSecondHalfArrayEle{
public static void main(String[] args)
{
int a[]={10,20,30,60,50,100,40,90};
int max=0,ele=a[0];
for(int i=0;i<a.length;i++){
if(a.length/2<i){
max=a[i];
if(ele<max){
ele=max;
}
}
}
System.out.println("Second half array position of max element
is.."+ele);
}
}
___________________________________________________________________________________
___________________________________________________________________________________
___________

28)WAP TO REPLACE ELEMENT OF AN ARRAY ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------

Answer:====class Replace {
public static void main(String[] args){

int a[]={10,20,30,40,50,60};
int b=3,re=100;

for(int i=0;i<a.length;i++){
if(a[b]==a[i]){
a[i]=re;
}
}
for(int i:a){
System.out.println(i);
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
________________

29)WAP TO PRINT HOW MANY TIME THE


GIVEN ELEMENT IS OCCURRED?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------------

Answer:======class GivenCountEle {
public static void main(String[] args){

int a[]={10,50,30,40,50,50,50};
int c=0,ele=50;

for(int i=0;i<a.length;i++){
if(a[i]==ele){
c++;

}
}

System.out.println("how meny times element is presents...."+c);

}
}

___________________________________________________________________________________
___________________________________________________________________________________
_____________

30)WAP TO PRINT HOW MANY TIMES THE


ELEMENTS ARE PRESENT ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------

Answer:======class CountEle {
public static void main(String[] args){

int a[]={10,50,30,40,50,50};
int c=0;

for(int i=0;i<a.length-1;i++){
for(int j=i+1;j<a.length;j++){
if(a[i]==a[j]){
c++;
}
}
}

System.out.println("how meny times element is presents...."+c);

}
}

___________________________________________________________________________________
___________________________________________________________________________________
__________________

31)WAP TO PRINT MISSNG ELEMENT IN A GIVEN SORTING


ARRAY?
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------------

Answer:=======

___________________________________________________________________________________
___________________________________________________________________________________
_______________

32)WAP TO REMOVE DUPLICATES FROM AN ARRAY ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------

Answer:=====

___________________________________________________________________________________
___________________________________________________________________________________
___________

33)WAP TO MERGE TWO ARRAY ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------

Answer:======class MargeArray {
public static void main(String[] args) {
int a[]={1,2,3,4,5,10};
int b[]={6,7,8,9,20};
int res[]=new int[a.length+b.length];
for(int i=0;i<a.length;i++){
res[i]=a[i];
}
for(int i=a.length,j=0;i<res.length;i++,j++){
res[i]=b[j];
}
for(int i=0;i<res.length;i++){

System.out.println(res[i]);
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
____________________

34)WAP TO ACHIEVE BUBBLE SORT ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------

Answer:======
class BoubleSort {
public static void main(String[] args){
int a[]={45,25,84,651,2};
int temp=0;
for(int i=0;i<a.length-1;i++){
for(int j=1;j<a.length-i;j++){
if(a[j]<a[j-1]){
temp=a[j];
a[j]=a[j-1];
a[j-1]=temp;
}
}
}
for(int i:a){

System.out.println(i);
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
________________

35)WAP TO PRINT ALL THE PRIME


NUMBERS PRESENT IN A ARRAY ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------

Answer:=======

class PrimeEle {
public static void main(String[] args) {
int a[]={1,2,3,4,5,6,7,8,9};
for(int i=0;i<a.length;i++){
int co=0;
for(int j=1;j<=a[i];j++){
if(a[i]%j==0){
co++;
}
}
if(co==2){
System.out.println("prime element is..."+a[i]);
}
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
_______________

36)WAP TO PRINT PALINDROME NUMBERS


PRESENT IN A ARRAY ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------

Answer:=======class Piliondrumele {
public static void main(String[] args) {
int a[]={121,234,45654,23,65};
for(int i=0;i<a.length;i++){
int sum=0,ele=a[i];
while(ele!=0){
int r=ele%10;
sum=sum*10+r;
ele=ele/10;
}
if(sum==a[i]){
System.out.println("pilindrom element
is..."+a[i]);
}
}

}
}

___________________________________________________________________________________
___________________________________________________________________________________
______________

37)WAP TO ADD AN ELEMENT INTO EXISTING


ARRAY IN A SPECIFIC POSITION ?
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------

Answer:======

___________________________________________________________________________________
___________________________________________________________________________________
____________________

38)WAP TO REMOVE AN ELEMENT INTO EXISTING


ARRAY IN A SPECIFIC POSITION ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------

Answer:=====

___________________________________________________________________________________
___________________________________________________________________________________
_________________

39)WAP TO SEARCH AN ELEMENT AND PRINT THE


POSITION OF THE ELEMENT?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------

Answer:======

___________________________________________________________________________________
___________________________________________________________________________________
______________

40)WAP TO ACHIEVE SELECTION SORT ?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------

Answer:=======class SelectionSort{
public static void main(String[] args)
{
int a[]={120,25,654,60,354};
for(int i=0;i<a.length-1;i++){
int min=i;
for(int j=i+1;j<a.length;j++){
if(a[min]>a[j]){
min=j;
}
}
int temp=a[i];
a[i]=a[min];
a[min ]=temp;
}
for(int i:a){

System.out.println(i);
}
}
}

___________________________________________________________________________________
___________________________________________________________________________________
______________

RECURSION:
----------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------

1)WAP TO PRINT NATURAL


NUMBERS FROM 1 TO 10 WITH THE HELP OF RECURSION?

-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------

Answer:==========

You might also like