Computer Applications
Write a java program to accept an integer. From it create a new integer by removing all zeros from it. For example, for the integer 20180 the new integer after removing all zeros from it will be 218. Print the original as well as the new integer.
Answer
import java.util.Scanner;
public class Kboat
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
System.out.print("Enter number: ");
int num = in.nextInt();
int idx = 0;
int newNum = 0;
int n = num;
while (n != 0) {
int d = n % 10;
if (d != 0) {
newNum += (int)(d * Math.pow(10, idx));
idx++;
}
n /= 10;
}
System.out.println("Original number = " + num);
System.out.println("New number = " + newNum);
}
}Output
Related Questions
Write a program in Java to find the Fibonacci series within a range entered by the user.
Sample Input:
Enter the minimum value: 10
Enter the maximum value: 20Sample Output:
13Rewrite the following do while program segment using for:
x = 10; y = 20; do { x++; y++; } while (x<=20); System.out.println(x * y );