Write a program to input an integer and remove all the even digits from it print the number in java
Answers
Answered by
1
Answer:
The only problem? The answer is in reverse order. I’ll let you figure out how to reverse the program logic. I tested the program on up to 12 digit numbers. An error is generated with 13–14 digit numbers. If an answer has more than ten digits, the answer will be displayed in scientific notation.
Explanation:
Attachments:
Answered by
9
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
English,
5 months ago
CBSE BOARD X,
5 months ago
Math,
5 months ago
Math,
11 months ago
CBSE BOARD X,
11 months ago
Biology,
1 year ago
Biology,
1 year ago