Notification texts go here Contact Us Buy Now!

Consider First n even numbers starting from zero(0).Complete the code segment to calculate sum of all the numbers divisible by 3 from 0 to n. Print the sum.

Consider First n even numbers starting from zero(0).Complete the code segment to calculate sum of all the numbers divisible by 3 from 0 to n. Print t

 import java.util.Scanner;

public class Exercise1_3 {

       public static void main(String[] args) {

   Scanner sc = new Scanner(System.in);

   int n=sc.nextInt();

  int sum=0;

//Use for or while loop do the operation.


int result=1;

int i=0;

while(result<=n)

{

if(i%2==0)

{

if(i%3==0)

{

sum=sum+i;

}

result=result+1;

}

i=i+1;

}


System.out.print(sum);

}

}

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.
Oops!
It seems there is something wrong with your internet connection. Please connect to the internet and start browsing again.
AdBlock Detected!
We have detected that you are using adblocking plugin in your browser.
The revenue we earn by the advertisements is used to manage this website, we request you to whitelist our website in your adblocking plugin.
Site is Blocked
Sorry! This site is not available in your country.