Check if a number can be written as sum of three consecutive integers | JAVA Code to check if a number can be written as sum of three consecutive integers . ; function to check if a number can be written as sum of three consecutive integers . ; if n is multiple of 3 ; else print " - 1" . ; Driver program to test above function
import java . util . * ; class GFG { static void checksum ( int n ) { if ( n % 3 == 0 ) System . out . println ( n / 3 - 1 + " ▁ " + n / 3 + " ▁ " + ( n / 3 + 1 ) ) ; else System . out . println ( " - 1" ) ; } public static void main ( String [ ] args ) { int n = 6 ; checksum ( n ) ; } }