Computer Science, asked by lakshmiPulapa, 3 months ago

given two integers x and k find the largest number that can be formed by changing digits at utmost K places in the number X​

Answers

Answered by beautybaral36
0

Answer:

'70_7%∆=×√•€¢÷π¢{$€=\[

Answered by udayagrawal49
1

Answer: The required Java program is :-

import java.util.Scanner;

public class Main {

public static void main (String [] args) {

    Scanner scan = new Scanner(System.in);

    System.out.print("Enter an integer X = ");

    String[] num = (""+scan.nextInt()).split("");

    System.out.print("Enter an integer K = ");

    int k = scan.nextInt();

 int n = num.length;

 for (int i=0 ; i<n ; i++) {

  if (k < 1) {

   break;

  }

  if (num[i].equals("9") == false) {

   num[i] = "9";

   k--;

  }

 }

 System.out.print(String.join("",num));

   }

}

Note :-

The above program is saved in a file named Main.java

Also, try-catch block can be used to avoid errors.

Similar questions