Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Searching value and Reverse code !!!!!!


public class FindandReverse {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

int i[] = {1,2,3,5,6};

int searchVal = 55;

boolean found = false;

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

if(i[a]==searchVal){

found = true;}
}

if(found){

System.out.println("We found the value "+ searchVal+ "! " );

}
else{

System.out.println("Can't find "+searchVal+ " in this array.");

}

// ********************************************************

int x= 123456;


int temp = 0;

int reverse = 0;

while(x>0){

temp = x%10; //get the value from right of x

reverse = reverse * 10 + temp; //add the value to the reverse
x = x/10; //remove the value from the x


} System.out.println("\n"+reverse);


}
}
_________________________________________________

Output:

Can't find 55 in this array.

654321




This post first appeared on LET's START CORE JAVA !, please read the originial post: here

Share the post

Searching value and Reverse code !!!!!!

×

Subscribe to Let's Start Core Java !

Get updates delivered right to your inbox!

Thank you for your subscription

×