import java.io.*;
class card
{
static char[]Suits=new char[21];
static char[]Number=new char[21];
static char[][]StacksS=new char[3][7];
static char[][]StacksN=new char[3][7];
public static void ReAdjust(int a, int b)
{
for(int i=0; i<=6; i++)
{
char A=StacksS[a][i];
StacksS[a][i]=StacksS[b][i];
StacksS[b][i]=A;
A=StacksN[a][i];
StacksN[a][i]=StacksN[b][i];
StacksN[b][i]=A;
}
}
public static void D2Stacks()
{
int k=0;
for(int i=0; i<=6; i++)
{
for(int j=0; j<3; j++)
{
StacksS[j][i]=Suits[k];
StacksN[j][i]=Number[k++];
}
}
}
public static void D2Pile()
{
int k=0;
for(int i=0; i<3; i++)
{
for(int j=0; j<7; j++)
{
Suits[k]=StacksS[i][j];
Number[k++]=StacksN[i][j];
}
}
}
public static void Display(int a)
{
for(int i=0; i<=6; i++)
{
for(int j=0; j<3; j++)
{
for(int v=0; v<=888888; v++)
System.out.print("");
System.out.print(""+StacksS[j][i]+""+StacksN[j][i]+" ");
}
}
System.out.println();
System.out.println("(Please note: C=Club, H=Heart, D=Diamond, S=Spade, T=10)");
}
public static void Display()
{
System.out.println("Stack-1 Stack-2 Stack-3");
for(int i=0; i<=6; i++)
{
for(int a=0; a<=888888; a++)
System.out.print("");
for(int j=0; j<3; j++)
{
System.out.print(""+StacksS[j][i]+""+StacksN[j][i]+" ");
}
System.out.println("");
}
}
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new
InputStreamReader(System.in));
char[][]A=new char[4][13];
char[]B={'H', 'S', 'D', 'C'};
char[]C={'A',50,51,52,53,54,55,56,57,'T','J','Q','K'};
for(int i=0; i<=3; i++)
for(int j=0; j<=12; j++)
A[i][j]=C[j];
int q, b, c=0;
for(c=0; c<=20; c++)
{
do{
q=(int)(Math.random()*4);
b=(int)(Math.random()*13);
}while(A[q][b]==' ');
Suits[c]=B[q];
Number[c]=A[q][b];
A[q][b]=' ';
}
D2Stacks();
System.out.println("Select a card from the following cards in your mind: ");
for(int a=0; a<=888888; a++)
System.out.print("");
Display(1);
System.out.println("\n\nNow press enter: ");
String S=br.readLine();
D2Pile();
D2Stacks();
System.out.println("\n\nSelect the stack in which your card lies this time around: ");
Display();
System.out.println("\n\nNow type the stack number and press enter: ");
int a=Integer.parseInt(br.readLine());
if(a!=2)
ReAdjust(1, a-1);
for(int p=0; p<=888888; p++)
System.out.print("");
D2Pile();
D2Stacks();
System.out.println("\n\nSelect the stack in which your card lies for the last time now: ");
Display();
System.out.println("\n\nNow type the stack number and press enter: ");
a=Integer.parseInt(br.readLine());
if(a!=2)
ReAdjust(1, a-1);
for(int p=0; p<=888888; p++)
System.out.print("");
D2Pile();
D2Stacks();
System.out.println("\n\nSelect the stack in which your card lies: ");
Display();
System.out.println("\n\nNow type the stack number and press enter: ");
a=Integer.parseInt(br.readLine());
if(a!=2)
ReAdjust(1, a-1);
for(int p=0; p<=888888; p++)
System.out.print("");
System.out.print("You selected .");
for(int i=1; i<=399999999; i++)
if(i%122222222==0)
System.out.print(" .");
System.out.print(" "+StacksS[1][3]+""+StacksN[1][3]);
}
}
This site has got programs, that u may need as an ISC student or a beginner. These are simple console based programs that can be run and understood by anyone having the idea of basic, core Java concepts. (java programs for beginners)
Thursday, February 16, 2012
Saturday, February 11, 2012
Java program to find the divisibility by 2 without using mod(%)
/**to find divisibility by 2 without using "%"
*/
public class Shivam
{
public static boolean check(int a)
{
if(a/2.0-a/2==0)
return true;
return false;
}
}
*/
public class Shivam
{
public static boolean check(int a)
{
if(a/2.0-a/2==0)
return true;
return false;
}
}
Recursive function in java to print all natural numbers from 1 upto (n-1)
// recursive func to print a series of natural nos. upto (x-1)
import java.io.*;
public class RecFUNCseries
{
public static void main(String args[]) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter an integer: ");
int x=Integer.parseInt(br.readLine());
series(x);
}
public static void series(int x)
{
if(x>0)
series(--x);
if(x!=0)
System.out.print(x+" ");
}
}
import java.io.*;
public class RecFUNCseries
{
public static void main(String args[]) throws IOException{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter an integer: ");
int x=Integer.parseInt(br.readLine());
series(x);
}
public static void series(int x)
{
if(x>0)
series(--x);
if(x!=0)
System.out.print(x+" ");
}
}
Java programs to find the coprimes of a number
// coprimes of any number n are numbers bw 1 and n, which are not divisible by any factors of n
public class Coprimes
{
public static void main(String args[])
{
int sum=0;
int p=0;
int y;
for(int i=18; i<=23; i++)
{
sum=0;
p=0;
int[]a=new int[i/2];
for(int j=2; j<=i/2; j++)
{
if(i%j==0 && IsPrime(j)==true)
a[p++]=j;
}
System.out.println("For "+i+", the co-primes are:");
for(int x=1; x {
for(y=0; y {
if(x%a[y]==0)
break;
}
if(y==p)
{
sum+=x;
System.out.println(x);
}
}
System.out.println("Their sum is "+sum);
System.out.println("");
System.out.println("");
}
}
public static boolean IsPrime(int a)
{
a=Math.abs(a);
for(int i=2; i<=a/2; i++)
if(a%i==0)
return false;
return true;
}
}
public class Coprimes
{
public static void main(String args[])
{
int sum=0;
int p=0;
int y;
for(int i=18; i<=23; i++)
{
sum=0;
p=0;
int[]a=new int[i/2];
for(int j=2; j<=i/2; j++)
{
if(i%j==0 && IsPrime(j)==true)
a[p++]=j;
}
System.out.println("For "+i+", the co-primes are:");
for(int x=1; x {
for(y=0; y {
if(x%a[y]==0)
break;
}
if(y==p)
{
sum+=x;
System.out.println(x);
}
}
System.out.println("Their sum is "+sum);
System.out.println("");
System.out.println("");
}
}
public static boolean IsPrime(int a)
{
a=Math.abs(a);
for(int i=2; i<=a/2; i++)
if(a%i==0)
return false;
return true;
}
}
Java Program to print the initials of a name with last name written in full
public class Initials
{
public static void initials(String S)
{
int[]A=new int[S.length()];
int sp=0;
for(int i=0; i
if(S.charAt(i)==' ')
A[sp++]=i;
if(sp==0)
System.out.println(S);
else
{
System.out.print(S.charAt(0)+". ");
for(int i=0; i
System.out.print(S.charAt(A[i]+1)+". ");
System.out.print(S.substring(S.lastIndexOf(' ')+1, S.length()));
}
}
}
{
public static void initials(String S)
{
int[]A=new int[S.length()];
int sp=0;
for(int i=0; i
A[sp++]=i;
if(sp==0)
System.out.println(S);
else
{
System.out.print(S.charAt(0)+". ");
for(int i=0; i
System.out.print(S.charAt(A[i]+1)+". ");
System.out.print(S.substring(S.lastIndexOf(' ')+1, S.length()));
}
}
}
Friday, February 10, 2012
Java program To remove duplicates from an array of integers so that each number may appear only once
// to delete the duplicates in n array so that a number may appear only once in the array
import java.io.*;
class remDup
{
public static void main(String args[]) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the length of the array: ");
int l=Integer.parseInt(br. readLine());
int[]a=new int[l];
for(int i=0; i<l; i++)
{
System.out.print("Enter the element number "+(i+1)+" of the array: ");
a[i]=Integer.parseInt(br. readLine());
}
//now the real work begins
for(int i=0; i<l; i++)
{
for(int j=i+1; j<l; j++)
{
while(a[i]==a[j])
{
for(int A=j; A<l-1; A++)
a[A]=a[A+1];
l--;
}
}
}
// real work is done now!!!!
for(int i=0; i<l; i++)
{
System.out.println(a[i]);
}
}// end of main
}// end of class
class remDup
{
public static void main(String args[]) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter the length of the array: ");
int l=Integer.parseInt(br.
int[]a=new int[l];
for(int i=0; i<l; i++)
{
System.out.print("Enter the element number "+(i+1)+" of the array: ");
a[i]=Integer.parseInt(br.
}
//now the real work begins
for(int i=0; i<l; i++)
{
for(int j=i+1; j<l; j++)
{
while(a[i]==a[j])
{
for(int A=j; A<l-1; A++)
a[A]=a[A+1];
l--;
}
}
}
// real work is done now!!!!
for(int i=0; i<l; i++)
{
System.out.println(a[i]);
}
}// end of main
}// end of class
Console based two-player Cross and Noughts game in Java
import java.io.*;
public class CrossZero
{
static char[][] A=new char[3][3];
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Player 1: X");
System.out.println("Player 2: O");
for(int i=0; i<=2; i++) for(int j=0; j<=2; j++) A[i][j]='*'; Print(); for(int i=1; i<=9; i++) { System.out.println("Player "+((i%2)==1?1:2)); System.out.println("Enter Row Number: "); int r=Integer.parseInt(br.readLine()); System.out.println("Enter Column Number: "); int c=Integer.parseInt(br.readLine()); if(i%2==1) A[r][c]='X'; else A[r][c]='O'; Print(); if(i>4)
{
if(check('X')==true||check('O')==true)
{
System.out.println("Congrats, You've Won");
break;
}
if(i==9)
System.out.println("Sorry dudes! No one won..");
}
}
}
public static void Print()
{
System.out.print(" ");
for(int i=0; i<=2; i++)
System.out.print(" "+i+" ");
System.out.println("");
System.out.println("");
for(int i=0; i<=2; i++)
{ for(int j=0; j<=2; j++)
if(j==0)
System.out.print(i+" "+A[i][j]);
else
System.out.print(" "+A[i][j]);
System.out.println("");
System.out.println("");
}
System.out.println("");
System.out.println("");
System.out.println("");
}
public static boolean check(char a)
{
for(int i=0; i<=2; i++)
{
if(A[i][0]==a&&A[i][1]==a&&A[i][2]==a)
return true;
if(A[0][i]==a&&A[1][i]==a&&A[2][i]==a)
return true;
}
if(A[0][0]==a&&A[1][1]==a&&A[2][2]==a)
return true;
if(A[0][2]==a&&A[1][1]==a&&A[2][0]==a)
return true;
return false;
}
}
public class CrossZero
{
static char[][] A=new char[3][3];
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Player 1: X");
System.out.println("Player 2: O");
for(int i=0; i<=2; i++) for(int j=0; j<=2; j++) A[i][j]='*'; Print(); for(int i=1; i<=9; i++) { System.out.println("Player "+((i%2)==1?1:2)); System.out.println("Enter Row Number: "); int r=Integer.parseInt(br.readLine()); System.out.println("Enter Column Number: "); int c=Integer.parseInt(br.readLine()); if(i%2==1) A[r][c]='X'; else A[r][c]='O'; Print(); if(i>4)
{
if(check('X')==true||check('O')==true)
{
System.out.println("Congrats, You've Won");
break;
}
if(i==9)
System.out.println("Sorry dudes! No one won..");
}
}
}
public static void Print()
{
System.out.print(" ");
for(int i=0; i<=2; i++)
System.out.print(" "+i+" ");
System.out.println("");
System.out.println("");
for(int i=0; i<=2; i++)
{ for(int j=0; j<=2; j++)
if(j==0)
System.out.print(i+" "+A[i][j]);
else
System.out.print(" "+A[i][j]);
System.out.println("");
System.out.println("");
}
System.out.println("");
System.out.println("");
System.out.println("");
}
public static boolean check(char a)
{
for(int i=0; i<=2; i++)
{
if(A[i][0]==a&&A[i][1]==a&&A[i][2]==a)
return true;
if(A[0][i]==a&&A[1][i]==a&&A[2][i]==a)
return true;
}
if(A[0][0]==a&&A[1][1]==a&&A[2][2]==a)
return true;
if(A[0][2]==a&&A[1][1]==a&&A[2][0]==a)
return true;
return false;
}
}
java program To print a Name in big letters/ To convert a name into large Letters
import java.io.*;
class better1
{
public static void main(String args[]) throws IOException
{
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a name:");
String S=br.readLine();
S=S.toLowerCase();
String D[][]=new String[26][8];
FileReader a=new FileReader("C:/MyFile.txt");//MyFile sent as an attachment
BufferedReader b=new BufferedReader(a);
for(int i=0; i< 26;i++)
for(int j=0; j< 8;j++)
D[i][j]=b.readLine();
for(int i=0; i<= 7; i++)
{
for(int j=0; j< S.length(); j++)
{
char ch=S.charAt(j);
int c=ch-97;
if(ch==' ')
System.out.print("--------");
else
System.out.print(D[c][i]+"-");
}
System.out.println("");
}
b.close();
a.close();
}
}
Copy the following text as it is and save it in a file named MyFile.txt in C drive.
Then run the program...
---AA---
--AAAA--
-AA--AA-
AA----AA
AAAAAAAA
AA----AA
AA----AA
AA----AA
BBBBBB--
BB---BB-
BB----BB
BB---BB-
BBBBBB--
BB----BB
BB---BB-
BBBBBB--
---CCCC-
-CC---CC
CC------
CC------
CC------
CC
-CC---CC
---CCCC-
DDDDD---
DD--DD--
DD---DD-
DD----DD
DD----DD
DD---DD-
DD--DD--
DDDDD---
EEEEEEEE
EE------
EE------
EEEEEEE-
EE------
EE------
EE------
EEEEEEEE
FFFFFFFF
FF------
FF------
FFFFFFF-
FF------
FF------
FF------
FF------
---GGGG-
--GG--GG
-GG-----
GG------
GG--GGGG
-GG---GG
--GG--GG
---GGGG-
HH----HH
HH----HH
HH----HH
HHHHHHHH
HHHHHHHH
HH----HH
HH----HH
HH----HH
IIIIIIII
---II---
---II---
---II---
---II---
---II---
---II---
IIIIIIII
JJJJJJJJ
---JJ---
---JJ---
---JJ---
---JJ---
J--JJ---
JJ-JJ---
-JJJJ---
KK----KK
KK---KK-
KK--KK--
KKKK----
KKKK----
KK--KK--
KK---KK-
KK----KK
LL------
LL------
LL------
LL------
LL------
LL------
LL------
LLLLLLLL
MM----MM
MM----MM
M-M--M-M
M--MM--M
M------M
M------M
M------M
M------M
NN-----N
NN-----N
N-N----N
N--N---N
N---N--N
N----N-N
N-----NN
N-----NN
--OOOO--
-OO--OO-
OO----OO
OO----OO
OO----OO
OO----OO
-OO--OO-
--OOOO--
PPPPPP--
PP---PP-
PP----PP
PP---PP-
PPPPPP--
PP------
PP------
PP------
--QQQQ--
-QQ--QQ-
QQ----QQ
QQQ---QQ
QQ-Q--QQ
QQ--Q-QQ
-QQ--QQ-
--QQQQ-Q
RRRRRR--
RR---RR-
RR----RR
RR---RR-
RRRRRR--
RR---RR-
RR----RR
RR----RR
--SSSS--
-SS---S-
SS------
--SSSS--
------S-
------SS
SS---SS-
-SSSSS--
TTTTTTTT
---TT---
---TT---
---TT---
---TT---
---TT---
---TT---
---TT---
UU----UU
UU----UU
UU----UU
UU----UU
UU----UU
UU----UU
UUU--UUU
-UUUUUU-
V----VV-
V----VVV
V-----V-
V-----V-
V-----V-
-V---V--
--V-V---
---V----
WW----WW
WW----WW
WW----WW
WW----WW
WW----WW
WW-WW-WW
WWW--WWW
WW----WW
XX----XX
-XX--XX-
--XX-X--
---XX---
--XX-XX-
-XX---XX
X-----XX
X------X
YY----YY
-YY--YY-
-YY--YY-
--YY-Y--
---YY---
---YY---
---YY---
---YY---
ZZZZZZZZ
------Z-
-----Z--
----Z---
---Z----
--Z-----
-Z------
ZZZZZZZZ
class better1
{
public static void main(String args[]) throws IOException
{
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a name:");
String S=br.readLine();
S=S.toLowerCase();
String D[][]=new String[26][8];
FileReader a=new FileReader("C:/MyFile.txt");//MyFile sent as an attachment
BufferedReader b=new BufferedReader(a);
for(int i=0; i< 26;i++)
for(int j=0; j< 8;j++)
D[i][j]=b.readLine();
for(int i=0; i<= 7; i++)
{
for(int j=0; j< S.length(); j++)
{
char ch=S.charAt(j);
int c=ch-97;
if(ch==' ')
System.out.print("--------");
else
System.out.print(D[c][i]+"-");
}
System.out.println("");
}
b.close();
a.close();
}
}
Copy the following text as it is and save it in a file named MyFile.txt in C drive.
Then run the program...
---AA---
--AAAA--
-AA--AA-
AA----AA
AAAAAAAA
AA----AA
AA----AA
AA----AA
BBBBBB--
BB---BB-
BB----BB
BB---BB-
BBBBBB--
BB----BB
BB---BB-
BBBBBB--
---CCCC-
-CC---CC
CC------
CC------
CC------
CC
-CC---CC
---CCCC-
DDDDD---
DD--DD--
DD---DD-
DD----DD
DD----DD
DD---DD-
DD--DD--
DDDDD---
EEEEEEEE
EE------
EE------
EEEEEEE-
EE------
EE------
EE------
EEEEEEEE
FFFFFFFF
FF------
FF------
FFFFFFF-
FF------
FF------
FF------
FF------
---GGGG-
--GG--GG
-GG-----
GG------
GG--GGGG
-GG---GG
--GG--GG
---GGGG-
HH----HH
HH----HH
HH----HH
HHHHHHHH
HHHHHHHH
HH----HH
HH----HH
HH----HH
IIIIIIII
---II---
---II---
---II---
---II---
---II---
---II---
IIIIIIII
JJJJJJJJ
---JJ---
---JJ---
---JJ---
---JJ---
J--JJ---
JJ-JJ---
-JJJJ---
KK----KK
KK---KK-
KK--KK--
KKKK----
KKKK----
KK--KK--
KK---KK-
KK----KK
LL------
LL------
LL------
LL------
LL------
LL------
LL------
LLLLLLLL
MM----MM
MM----MM
M-M--M-M
M--MM--M
M------M
M------M
M------M
M------M
NN-----N
NN-----N
N-N----N
N--N---N
N---N--N
N----N-N
N-----NN
N-----NN
--OOOO--
-OO--OO-
OO----OO
OO----OO
OO----OO
OO----OO
-OO--OO-
--OOOO--
PPPPPP--
PP---PP-
PP----PP
PP---PP-
PPPPPP--
PP------
PP------
PP------
--QQQQ--
-QQ--QQ-
QQ----QQ
QQQ---QQ
QQ-Q--QQ
QQ--Q-QQ
-QQ--QQ-
--QQQQ-Q
RRRRRR--
RR---RR-
RR----RR
RR---RR-
RRRRRR--
RR---RR-
RR----RR
RR----RR
--SSSS--
-SS---S-
SS------
--SSSS--
------S-
------SS
SS---SS-
-SSSSS--
TTTTTTTT
---TT---
---TT---
---TT---
---TT---
---TT---
---TT---
---TT---
UU----UU
UU----UU
UU----UU
UU----UU
UU----UU
UU----UU
UUU--UUU
-UUUUUU-
V----VV-
V----VVV
V-----V-
V-----V-
V-----V-
-V---V--
--V-V---
---V----
WW----WW
WW----WW
WW----WW
WW----WW
WW----WW
WW-WW-WW
WWW--WWW
WW----WW
XX----XX
-XX--XX-
--XX-X--
---XX---
--XX-XX-
-XX---XX
X-----XX
X------X
YY----YY
-YY--YY-
-YY--YY-
--YY-Y--
---YY---
---YY---
---YY---
---YY---
ZZZZZZZZ
------Z-
-----Z--
----Z---
---Z----
--Z-----
-Z------
ZZZZZZZZ
Wednesday, February 8, 2012
java program To find the coprimes of a number
// coprimes of any number n are numbers bw 1 and n, which are not divisible by any factors of n
public class Coprimes
{
public static void main(String args[])
{
int sum=0;
int p=0;
int y;
for(int i=18; i<=23; i++)
{
sum=0;
p=0;
int[]a=new int[i/2];
for(int j=2; j<=i/2; j++)
{
if(i%j==0 && IsPrime(j)==true)
a[p++]=j;
}
System.out.println("For "+i+", the co-primes are:");
for(int x=1; x {
for(y=0; y {
if(x%a[y]==0)
break;
}
if(y==p)
{
sum+=x;
System.out.println(x);
}
}
System.out.println("Their sum is "+sum);
System.out.println("");
System.out.println("");
}
}
public static boolean IsPrime(int a)
{
a=Math.abs(a);
for(int i=2; i<=a/2; i++)
if(a%i==0)
return false;
return true;
}
}
public class Coprimes
{
public static void main(String args[])
{
int sum=0;
int p=0;
int y;
for(int i=18; i<=23; i++)
{
sum=0;
p=0;
int[]a=new int[i/2];
for(int j=2; j<=i/2; j++)
{
if(i%j==0 && IsPrime(j)==true)
a[p++]=j;
}
System.out.println("For "+i+", the co-primes are:");
for(int x=1; x {
for(y=0; y {
if(x%a[y]==0)
break;
}
if(y==p)
{
sum+=x;
System.out.println(x);
}
}
System.out.println("Their sum is "+sum);
System.out.println("");
System.out.println("");
}
}
public static boolean IsPrime(int a)
{
a=Math.abs(a);
for(int i=2; i<=a/2; i++)
if(a%i==0)
return false;
return true;
}
}
java program: Recursive function to multiply two numbers
// to multiply 2 nos. using recursive functions
import java.io.*;
class recursiveMultiplication
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter a number: ");
String s=br.readLine();
System.out.print("Enter another number: ");
String S=br.readLine();
int a=Integer.parseInt(s);
int b=Integer.parseInt(S);
if((a<0&&b>0)||(a>0&&b<0))
System.out.print(-Mult(Math.abs(a),Math.abs(b)));
else System.out.print(Mult(Math.abs(a),Math.abs(b)));
}
public static int Mult(int a, int b)
{
if(a==0||b==0)
return 0;
else if(b==1)
return a;
return(a+Mult(a,(b-1)));
}
}
import java.io.*;
class recursiveMultiplication
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter a number: ");
String s=br.readLine();
System.out.print("Enter another number: ");
String S=br.readLine();
int a=Integer.parseInt(s);
int b=Integer.parseInt(S);
if((a<0&&b>0)||(a>0&&b<0))
System.out.print(-Mult(Math.abs(a),Math.abs(b)));
else System.out.print(Mult(Math.abs(a),Math.abs(b)));
}
public static int Mult(int a, int b)
{
if(a==0||b==0)
return 0;
else if(b==1)
return a;
return(a+Mult(a,(b-1)));
}
}
java program To print a String in reverse order using recursion
// to print a string in reverse order using recursion
import java.io.*;
class reverseString
{
public static void main(String args[])throws IOException
{
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter a String: ");
String s=br.readLine();
reverse(s, s.length());
}
public static void reverse(String S, int a)throws IOException
{
System.out.print(S.charAt(--a));
if(a>0)
reverse(S,a);
}
}
import java.io.*;
class reverseString
{
public static void main(String args[])throws IOException
{
BufferedReader br =new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter a String: ");
String s=br.readLine();
reverse(s, s.length());
}
public static void reverse(String S, int a)throws IOException
{
System.out.print(S.charAt(--a));
if(a>0)
reverse(S,a);
}
}
Subscribe to:
Posts (Atom)