Write a program to input an integer and remove all the even digits from it
Answers
Answered by
0
Question:
Write a program to input an integer and remove all the even digits from it.
Solution:
import java.util.*;
public class Question29
{
static void main()
{
Scanner sc=new Scanner(System.in);
int i,n,d,c=0,s=0;
System.out.println("Enter an integer:");
n=sc.nextInt();
while(n!=0)
{
d=n%10;
if(d%2!=0)
s=s+d*(int)Math.pow(10,c++);
n=n/10;
}
System.out.println("New Number="+s);
}
}
Similar questions