You are here: Home / Topics / Write a program which triples (*3) every third element, starting with 0, in the existing array named array.

Write a program which triples (*3) every third element, starting with 0, in the existing array named array.

Filed under: Java on 2024-02-27 12:51:08

Below program will do the needful task. There might be some other ways to do so as well. 

 

package day12Project;

public class Main {
public static void main(String[] args) {
 int[] arr = {1000,2,3,4,5,6,7,8,900,34,353,24,534,245,345,342,5435,343,53,423,24,353};
 for (int i = 2; i < arr.length; i = i+3) {
  System.out.println(arr[i]*3);
 }
}
}

About Author:
J
Java     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.