public static void main(String[] args) { int f = 0; int g = 1; for(int i = 1; i <= 10; i++) { System.out.print(f + " "); f = f + g; g = f - g; } System.out.println(); }
Wednesday, September 25, 2013
Fibnocci series easiest way...
Easiest way to reverse string in java and check for palindrome...
class RevString
{
static String reverse(String str) {
char[] c = str.toCharArray();
char[] r = new char[c.length];
int end = c.length - 1;
for (int n = 0; n <= end; n++) {
r[n] = c[end - n];
}
return new String(r);
}
bool isPalindrome(string str) {
int end= str.length();
for (int i=0;i<(end/ 2)+ 1;++i) {
if (str.charAt(i) != str.charAt(end- i - 1)) {
return false;
}
}
return true;
}
public static void main (String[] args)
{
System.out.println(RevString.reverse("hello"));
System.out.println(RevString.isPalindrome("liril"));
}
}
{
static String reverse(String str) {
char[] c = str.toCharArray();
char[] r = new char[c.length];
int end = c.length - 1;
for (int n = 0; n <= end; n++) {
r[n] = c[end - n];
}
return new String(r);
}
bool isPalindrome(string str) {
int end= str.length();
for (int i=0;i<(end/ 2)+ 1;++i) {
if (str.charAt(i) != str.charAt(end- i - 1)) {
return false;
}
}
return true;
}
public static void main (String[] args)
{
System.out.println(RevString.reverse("hello"));
System.out.println(RevString.isPalindrome("liril"));
}
}
Subscribe to:
Posts (Atom)
-
Association, Aggregation, Composition, Abstraction, Generalization, Realization, Dependency....go to below link... http://javapapers.co...
-
EJB Interview Question and Answer Question1: What do you mean by EJB? Ans: Most of the time this EJB interview questions is the...