the transformation of two integers into double in java

Your code looks sound, just a small tweek I would make. Your variable c will equal what you want b to be after it’s done dividing so you can just use it directly. Otherwise, you don’t really need to be using Integer.MAX_VALUE at all. Just use arbitrary values.

public class Functionality
{
  public static double createDouble(int a, int b) {
    double c = b;
    while(c >= 1)
      c /= 10;
    return a + c;
  }
  
  public static void main(String[] args) {
    System.out.println(createDouble(15, 351));
    System.out.println(createDouble(32, 8452));
  }
}

Output:

15.351
32.8452

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top