The following code does sum of the triples of even integersfrom 1 through 10

int total = 0;

for (int x = 1; x <= 10; x++){

if (x % 2 == 0)

{ // if x is even

total += x * 3;

}

}// end of for

Please rewrite the above code using InStream

Answer :

sandlee09

Answer:

Explanation:

Using Java, I have recreated that same code using intStream as requested. The code can be seen below and the output can be seen in the attached picture where it is highlighted in red.

import java.util.stream.IntStream;

class Brainly

{

   static int total = 0;

   public static void main(String[] args)

   {

       IntStream.range(0, 10).forEach(

               element -> {

                   if (element % 2 == 0) {

                       total += 3;

                   }

               }

       );

       System.out.println("Total: " + total);

   }

}

${teks-lihat-gambar} sandlee09

Other Questions