-2

class Geeks{

static void printInFormat(float a, float b){
    float num = a/b;
    System.out.format("%.7f %.3f\n",num,num); 

please make me understand last line I am new in java not getting this.

Alisha
  • 1
  • 3
    Possible duplicate of [How to format strings in Java](https://stackoverflow.com/questions/6431933/how-to-format-strings-in-java) – Lino May 01 '19 at 08:41
  • Read a bit through that link, you'll see lots of explanations. – Lino May 01 '19 at 08:41

1 Answers1

0

The first %.7f takes the first argument (float) rounds it to the 7th digit and inserts it into the result String e.g. : 1.12345678 -> 1.1234568
1.12345671 -> 1.1234567

The same goes for the second one

You can have the same results with : System.out.format("%.7f %.3f\n",num);

The format function has this documentation : https://docs.oracle.com/javase/8/docs/api/java/io/PrintStream.html#format-java.lang.String-java.lang.Object...-

loser8
  • 362
  • 3
  • 14