EduLearn - Online Education Platform

Welcome to EduLearn!

Start learning today with our wide range of courses taught by industry experts. Gain new skills, advance your career, or explore new interests.

Browse Courses

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

}

  1. 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);

}

}

 

Remove the specific number in java

Leave a Reply

Your email address will not be published. Required fields are marked *

EduLearn - Online Education Platform

Welcome to EduLearn!

Start learning today with our wide range of courses taught by industry experts. Gain new skills, advance your career, or explore new interests.

Browse Courses

Popular Courses

[Course Image]

Introduction to Programming

Learn the fundamentals of programming with Python in this beginner-friendly course.

12 Hours Beginner
[Course Image]

Data Science Essentials

Master the basics of data analysis, visualization, and machine learning.

20 Hours Intermediate
[Course Image]

Web Development Bootcamp

Build modern websites with HTML, CSS, JavaScript and popular frameworks.

30 Hours Beginner
[Course Image]

Digital Marketing Fundamentals

Learn SEO, social media marketing, email campaigns and analytics.

15 Hours Beginner
Educational Website Footer