AF
HomeTagSubmit NotesAsk AnythingLoginSubscribe Us
AF
1. Feel Free to ask and submit anything on Anyforum.in and get satisfactory answer
2. Registration is not compulsory, you can directly login via google or facebook
3. Our Experts are looking for yours ?.



corejava-programming: Print the sum of following numbers

Write a program in Java to print the sum of all numbers from 50 to 250 (inclusive of 50 and 250) that are multiples of 3 and not divisible by 9.

Input specification:

There should be no input from the user.

Output specification:

The sum of integers from 50 to 250 that are multiples of 3 and not divisible by 9 followed by a new line.

corejava x 333
programming x 150
Posted On : 2016-08-02 23:05:06.0
profile Boopalan - anyforum.in Boopalan
3730
up-rate
2
down-rate

Answers


public class PrintNumbers
{
public static void main(String arg[])
{

int sum=0;

for(int i=50;i<251;i++) //For-loop for numbers 50-250
{

if(i%3==0 & i%9!=0) // Condition to check if number should be divided by 3 and not divided by 9
{

System.out.println(i); //Individual number which are selected in loop

sum=sum+i; //Adding values of array so that total sum can be calculated
}
}
//Final display output for the code

System.out.println("\n The sum of intergers from 50 to 250 that are multiples of 3 and not divisible by 9 :" +sum);

}
}

Posted On : 2016-08-03 08:29:54
Satisfied : 1 Yes  0 No
profile MOHAMMAD SALEEM BASHA - anyforum.in MOHAMMAD SALEEM BASHA
266150
Reply This Thread
up-rate
6
down-rate

public class PrintNumbers
{
public static void main(String arg[])
{
int sum=0;
for(int i=50;i<=250;i++){ //For-loop for numbers 50-250
if(i%3==0 & i%9!=0){ // Condition to check if number should be divided by 3 and not divided by 9
sum=sum+i; //Adding values of array so that total sum can be calculated
}
}
System.out.println(sum);
}
}

Posted On : 2016-08-03 11:48:05
Satisfied : 1 Yes  0 No
profile Rishi Kumar - anyforum.in Rishi Kumar
523185418912
Reply This Thread
up-rate
5
down-rate



Post Answer
Please Login First to Post Answer: Login login with facebook - anyforum.in