Remove the specific number from the given input
i/p:1200
number to remove:2
output: 100
class Remove
{
public static void main(String args[])
{
int n=1200,r=2,a,s=0,b=1;
while(n!=0)//1
{
a=n%10;//a=1
if(a!=r)//1!=2(t)
{
s=s+b*a;//0+100*1–>s=100
b=b*10;//b=1000
}
n=n/10;//0
}
- System.out.println(s);//100
}
}
β Java Program: Remove a Specific Digit from Input
import java.util.Scanner;
public class RemoveDigitFromInput {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
// Input string (e.g., 1/p:1200)
System.out.print(“Enter the input (e.g., 1/p:1200): “);
String input = scanner.nextLine();
// Input number to remove (e.g., 2)
System.out.print(“Enter the digit to remove: “);
char digitToRemove = scanner.next().charAt(0);
// Extract only the number part after ‘:’
String[] parts = input.split(“:”);
if (parts.length != 2) {
System.out.println(“Invalid input format. Expected format like 1/p:1200”);
return;
}
String numberPart = parts[1];
// Remove the specific digit
String result = numberPart.replace(Character.toString(digitToRemove), “”);
System.out.println(“Output: ” + result);
}
}