Wednesday, November 2, 2011

Monday, October 17, 2011

Encode Image to BASE64 and Decode it- ANDROID (JAVA)

As of my Personal Experience, I am attaching a Base 64 file with my this post to convert Image to BASE64 and decode back. I have not written this Base 64 file but have taken a reference from other.


Download here

Thursday, September 29, 2011

To check number is odd or even without using OPERATOR( C++)

Hint: When we do conversion from decimal to binary then you have noticed that last digit of binary number is '0' if number is even ELSE '1'.
Using same logic we will solve this program.

#include "iostream.h"
#include "conio.h"
void main()
{
int number, last_digit;
cout<<"Enter the Number"; cin>>number;

last_digit=number & 1; //Give the last digit of Binary number

if(last_digit==0)
cout<<"Number is EVEN";

else
cout<<"Number is ODD";
}

Sunday, July 10, 2011

To change case of String

INPUT: JavA MaDe eASY

OUTPUT: jAVa mAdE Easy



class StringDemochangecase
{
static String changecase(String s)
{
String s1="";

for(int i=0;i {
char ch;
if(s.charAt(i)<91)
{
int c=s.charAt(i)+32;
ch=(char)c;
}
else
{
int c=s.charAt(i)-32;
ch=(char)c;
}
s1=s1+ch;
}
return s1;
}

public static void main(String args[])
{
String s="JavA MaDe eASY";
String s1=changecase(s);
System.out.println(s1);
}
}

Saturday, July 9, 2011

To check whether String is Palindrome or Not

public class StringDemopalindrome
{
static boolean palindrome(String s)
{
String s1="";
int i, flag=0;

for(i=s.length()-1;i>=0;i--)
{
s1=s1+s.charAt(i);
}

for(i=0;i {
if (s.charAt(i)!=s1.charAt(i))
flag =1;
}

if(flag==1)
return false;
else
return true;
}

public static void main(String args[])
{
String s="madam";
boolean b=palindrome(s);
System.out.println(b);
}
}

Calculate Length of String

public class StringDemolength
{
static int length(String s)
{
int i,count=0;
for(i=0;i {
count++;
}
return count;
}

public static void main(String args[])
{
String s="India is a good country";
int count=length(s);
System.out.println(count);
}
}

Print String in Reverse Order

INPUT: INDIA

OUTPUT: AIDNI

public class StringDemoReverse
{
static String reverse(String s)
{
int i;
String s1="";
for(i=s.length()-1;i>=0;i--)
{
s1=s1+s.charAt(i);
}
return s1;
}

public static void main(String args[])
{
String s="India";
String s1=reverse(s);
System.out.println(s1);
}
}

Saturday, June 11, 2011

Swap Two Images on button click in JAVA

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

class MyCanvas extends Canvas
{
Image i,j;
int flag;
MyCanvas()
{
Toolkit t= Toolkit.getDefaultToolkit();
i=t.getImage("f:\\hope.jpg"); //PATH OF FIRST IMAGE
j=t.getImage("f:\\Every_step.jpg"); //PATH OF SECOND IMAGE
}

public void paint(Graphics g)
{
if(flag==0)
{
g.drawImage(i,50,50,this);
g.drawImage(j,300,50,this);
}
if (flag==1)
{
g.drawImage(i,300,50,this);
g.drawImage(j,50,50,this);
}
}
}

class SwapImages implements ActionListener
{
MyCanvas m= new MyCanvas();
JFrame jf;
SwapImages()
{
jf=new JFrame("SWAP IMAGES");
jf.add(m);
JButton button1=new JButton("Swap");
Panel p=new Panel();
p.add(button1);
jf.add(p,BorderLayout.SOUTH);
button1.addActionListener(this);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setSize(400,400);
jf.setVisible(true);
}

public void actionPerformed(ActionEvent e)
{
if(m.flag==0)
m.flag=1;
else
m.flag=0;
m.repaint();
}

public static void main(String s[])
{
new SwapImages();
}
}

Thursday, May 19, 2011

Swap two numbers without using third variable

Example:
Before Swap
number1=45 number2=33

After Swap
number1=33 number2=45



class Swap {
public static void main(String[] args) {
int number1=45,number2=33;
number1 = number1 + number2;
number2 = number1 - number2;
number1 = number1 - number2;
System.out.println("After swapping, number1= " + number1 + " and number2= "
+ number2);
}
}

Tuesday, May 17, 2011

Summation of elements of upper triangle of matrix

Example:
1 2 3
0 4 5
0 0 6
public class arraydemotriangleBsum {

static void triangleBsum(int x[][])
{
int i,j,c=0;
for(i=0;i<3;i++) { for(j=0;j<3;j++) { if(i>=j)
{
c=c+x[i][j];
}
}
}
System.out.println("The Sum of triangle B is:"+c);
}
public static void main(String[] args)
{
triangleBsum(new int[][]{{1,2,3},{4,5,6},{7,8,9}});
}

}