Computer Science, asked by anitasrivastava404, 4 hours ago

write a program in Java to accept the length of a rope in cm and convert the length inte Km, metse and cm. Length of rope = 449 325 cm.​

Answers

Answered by anindyaadhikari13
7

Solution.

The given co‎‎de is written in Java.

import java.util.*;

public class Converter{

   public static void main(String s[]){

       int cm,m,km;

       System.out.print("Enter length of the rope in cm: ");

       cm=(new Scanner(System.in)).nextInt();

       System.out.print(cm+" cm = ");

       km=cm/100000;

       cm-=km*100000;

       m=cm/100;

       cm-=m*100;

       System.out.print(km+" km "+m+" m "+cm+" cm.");

   }

}

Logic.

  • Accept the length in cm.
  • Divide the length by 10⁵ to get the distance in km and store the result in variable 'km'.
  • Subtract the length by km * 100000.
  • Divide the length by 100 to get the distance in metres.
  • Again, subtract the length by m * 100 to get the distance in cm.
  • Now, display the result.

See the attachment for output.

Attachments:

anindyaadhikari13: Thanks for the brainliest :)
Similar questions