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