Untitled
Untitled
________________________________
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
}
}
___________________________________________________________________________________
___________________________________
-----------------------------------------------------------------------------------
--------------------------------
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);
}
}
___________________________________________________________________________________
______________________________________
-----------------------------------------------------------------------------------
---------------------------------------
Answer:==== class EvenOrOdd{
public static void main(String[] args){
int num=123454;
if(num%2==0){
___________________________________________________________________________________
______________________________________
-----------------------------------------------------------------------------------
----------------------------------------
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{
___________________________________________________________________________________
____________________________________________________
-----------------------------------------------------------------------------------
-----------------------------------------------------------
Answer:===
class Learg{
public static void
main(String[] args){
int
a=123,b=234,c=237;
if(a>b){
if(a>c){
}
else{
System.out.println(" c is leargest number :"+c);
else{
if(b>c){
else{
}
}
}
}
___________________________________________________________________________________
______________________________________
-----------------------------------------------------------------------------------
----------------------------------------------------
Answer:===
class Small{
public static void main(String[] args){
int
a=123,b=234,c=237;
if(a<b){
if(a<c){
}
else{
else{
if(b<c){
else{
}
}
}
}
___________________________________________________________________________________
_____________________________________________
CONDITIONAL OPERATOR:
----------------------
-----------------------------------------------------------------------
---------------------------------------------
-----------------------------------------------------------------------------------
-----------------------------------------------
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);
___________________________________________________________________________________
________________________________________________________
-----------------------------------------------------------------------------------
-------------------------------------------------
___________________________________________________________________________________
_______________________________________________________
-----------------------------------------------------------------------------------
-----------------------------------------------------
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);
___________________________________________________________________________________
____________________________________________________
-----------------------------------------------------------------------------------
---------------------------------------------------
___________________________________________________________________________________
_______________________________________________
IF-ELSE:
---------
-----------------------------------------------------------------------------
-----------------------------------
___________________________________________________________________________________
___________________________________________________________
-----------------------------------------------------------------------------------
-----------------------------------------------------
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);
}
}
}
___________________________________________________________________________________
________________________________________________________
-----------------------------------------------------------------------------------
-------------------------------------------------------
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{
___________________________________________________________________________________
______________________________________________________________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------
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{
___________________________________________________________________________________
________________________________________________________________________
-----------------------------------------------------------------------------------
-------------------------------------------------------------------------
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);
}
}
}
___________________________________________________________________________________
______________________________________________________________________
-----------------------------------------------------------------------------------
----------------------------------------------------------------------
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);
}
}
}
___________________________________________________________________________________
_________________________________________________________________________
-----------------------------------------------------------------------------------
-------------------------------------------------------------------------------
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);
}
}
}
___________________________________________________________________________________
_____________________________________________________________________________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------
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);
}
}
}
___________________________________________________________________________________
____________________________________________________________________________
-----------------------------------------------------------------------------------
--------------------------------------------------------------------------
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);
}
}
}
___________________________________________________________________________________
________________________________________________________________________________
-----------------------------------------------------------------------------------
-------------------------------------------------------------------------------
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);
}
}
___________________________________________________________________________________
________________________________________________________________________________
-----------------------------------------------------------------------------------
-------------------------------------------------------------------------------
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);
}
}
___________________________________________________________________________________
_____________________________________________________________________________
-----------------------------------------------------------------------------------
--------------------------------------------------------------------------------
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{
if(b<c){
}
else{
___________________________________________________________________________________
___________________________________________________________________________________
___
SWITCH
-------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---
-----------------------------------------------------------------------------------
----------------------------------------------------------------------------
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:{
___________________________________________________________________________________
___________________________________________________________________________________
_____
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------
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 ");
}
}
}
}
___________________________________________________________________________________
_________________________________________________________________________________
-----------------------------------------------------------------------------------
-------------------------------------------------------------------------------
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 ");
}
}
}
}
___________________________________________________________________________________
______________________________________________________
_________________________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
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 ");
}
}
}
}
___________________________________________________________________________________
________________________________________________________________________
-----------------------------------------------------------------------------------
--------------------------------------------------------------------
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 ");
}
}
}
}
___________________________________________________________________________________
____________________________________________________________________________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-
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 ");
}
}
}
}
___________________________________________________________________________________
________________________________________________________________________________
-----------------------------------------------------------------------------------
------------------------------------------------------------------------------
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
------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------
Answer:===class Natural{
public static void main(String[] args){
int n=1;
while(10>=n){
System.out.println(n++);
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
_________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------
Answer:===class NNatural{
public static void main(String[] args){
int n=1234;
for(int i=1;i<=n;i++){
System.out.println(i);
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
__________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----
___________________________________________________________________________________
___________________________________________________________________________________
______
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------
Answer:=======class Alphabet{
public static void main(String[] args){
for(char ch='A';ch<='Z';ch++){
System.out.print(" "+ch+" ");
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
_____________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------------
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));
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
_____________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------------
Answer:====class AlphaNum{
public static void main(String[] args){
for(int i=1;i<=26;i++){
System.out.println((char)(i+64)+"
"+i);
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
__________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------
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));
}
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
_____________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------
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);
}
___________________________________________________________________________________
___________________________________________________________________________________
____
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);
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
________
-----------------------------------------------------------------------------------
-------------------------------------------------------------------------------
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);
___________________________________________________________________________________
___________________________________________________________________________________
_____________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------
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);
}
}
___________________________________________________________________________________
___________________________________________________________________________________
_____________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------
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);
}
}
___________________________________________________________________________________
___________________________________________________________________________________
___________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------
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);
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
_____________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------
Answer:=====import java.util.Scanner;
class UserInput{
public static void
main(String[] args){
Scanner sc=new
Scanner(System.in);
System.out.println(num+"*"+i+"="+(num*i));
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
______
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----
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");
}
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------
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 ?
-----------------------------------------------------------------------------------
---------------------------------------------------------------------------------
}
System.out.println(" sum of 5
deviders.."+sum);
}
}
___________________________________________________________________________________
___________________________________________________________________________________
______
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---
Answer:====class quoeitent{
public static void main(String[]
args){
int num=85;
if(num%5==0){
System.out.println(85/5);
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
_________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------------
Answer:=====class quoeitent1{
public static void
main(String[] args){
System.out.println(85/5);
}
}
___________________________________________________________________________________
___________________________________________________________________________________
_______________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------
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;
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
________________
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;
}
___________________________________________________________________________________
___________________________________________________________________________________
___________________
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;
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
_______________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------
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;
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
______________
-----------------------------------------------------------------------------------
---------------------------------------------------------------------------
Answer:===class Unit{
public static void main(String[] args){
int num=123456;
System.out.println(num%10+" last unites
place");
}
}
___________________________________________________________________________________
___________________________________________________________________________________
_____
_----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--
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");
}
}
___________________________________________________________________________________
___________________________________________________________________________________
__________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----
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){
___________________________________________________________________________________
___________________________________________________________________________________
___
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);
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
____
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------
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){
}
else{
}
}
___________________________________________________________________________________
___________________________________________________________________________________
_______________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------
while(i>0){
int r=i%10;
if(r==7){
i=i/10;
___________________________________________________________________________________
___________________________________________________________________________________
______________________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------
Answer:=====class numberinit{
public static void
main(String[] args){
int co=0;
for(int i=10;i<=50;i++){
if(digit(i)>0){
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++;
}
}
}
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++;
}
}
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 :
-----------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------
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;
}
___________________________________________________________________________________
___________________________________________________________________________________
__________________
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){
___________________________________________________________________________________
___________________________________________________________________________________
______________
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;
}
___________________________________________________________________________________
___________________________________________________________________________________
_________________
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;
}
___________________________________________________________________________________
___________________________________________________________________________________
_____________________
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);
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
__________________
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){
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
____________________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------------
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){
___________________________________________________________________________________
___________________________________________________________________________________
______________
___________________________________________________________________________________
___________________________________________________________________________________
________________
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){
___________________________________________________________________________________
___________________________________________________________________________________
____________________
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;
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
_____________________
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){
}
else{
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
___________________
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){
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){
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){
___________________________________________________________________________________
___________________________________________________________________________________
___________________
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){
else{
}
}
___________________________________________________________________________________
___________________________________________________________________________________
____________
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){
}
}
___________________________________________________________________________________
___________________________________________________________________________________
_________________
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);
}
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
__________________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------
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){
}
}
___________________________________________________________________________________
___________________________________________________________________________________
________________
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){
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
_________________
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){
}
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
___________________
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
------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------
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);
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
____________________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------------
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];
___________________________________________________________________________________
___________________________________________________________________________________
______________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------
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]);
}
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
__________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------
Answer:=======
import
java.util.Scanner;
class ArraySumElements
{
public static void
main(String[] args){
Scanner sc=new
Scanner(System.in);
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);
sum=sum+a[i];
}
System.out.println("
avareage of array elements "+sum/n);
}
}
___________________________________________________________________________________
___________________________________________________________________________________
_________________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------
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);
}
}
___________________________________________________________________________________
___________________________________________________________________________________
___________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------
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);
}
}
___________________________________________________________________________________
___________________________________________________________________________________
__________________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------
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);
}
}
___________________________________________________________________________________
___________________________________________________________________________________
______________________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------------
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!");
}
}
___________________________________________________________________________________
___________________________________________________________________________________
______________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------
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!");
}
}
___________________________________________________________________________________
___________________________________________________________________________________
___________________
_----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------
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!");
}
}
___________________________________________________________________________________
___________________________________________________________________________________
____________________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------
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!");
}
}
___________________________________________________________________________________
___________________________________________________________________________________
_________________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------
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]);
}
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
_________________
___________________________________________________________________________________
___________________________________________________________________________________
_________________
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);
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
__________________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------------------
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+" ");
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
__________________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------
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);
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
_________________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------------
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]);
}
}
___________________________________________________________________________________
___________________________________________________________________________________
________________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------------
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]);
}
}
___________________________________________________________________________________
___________________________________________________________________________________
__________________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------
}
}
___________________________________________________________________________________
___________________________________________________________________________________
______________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------
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);
}
}
___________________________________________________________________________________
___________________________________________________________________________________
_________________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------
___________________________________________________________________________________
___________________________________________________________________________________
__________________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------
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);
}
}
___________________________________________________________________________________
___________________________________________________________________________________
_________________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------------
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);
}
}
___________________________________________________________________________________
___________________________________________________________________________________
___________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------
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);
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
________________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
--------------
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++;
}
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
_____________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------
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++;
}
}
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
__________________
Answer:=======
___________________________________________________________________________________
___________________________________________________________________________________
_______________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------
Answer:=====
___________________________________________________________________________________
___________________________________________________________________________________
___________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
------------
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]);
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
____________________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------
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);
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
________________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------
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]);
}
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
_______________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------
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]);
}
}
}
}
___________________________________________________________________________________
___________________________________________________________________________________
______________
Answer:======
___________________________________________________________________________________
___________________________________________________________________________________
____________________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------
Answer:=====
___________________________________________________________________________________
___________________________________________________________________________________
_________________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-----------------
Answer:======
___________________________________________________________________________________
___________________________________________________________________________________
______________
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
---------
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:
----------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
-------------
-----------------------------------------------------------------------------------
-----------------------------------------------------------------------------------
----------------
Answer:==========