Computer Science, asked by Anonymous, 11 months ago

Print the numbers divisible by 7 between 40 and 150

Answers

Answered by duragpalsingh
4

Hey there!

I'm performing this task using Java. This program is based on Looping.

It must be noted that loop variable will start from 40 and it will run unless the value of loop variable becomes 150.

Here, i'm taking 'i' as the loop variable and '%' operator will be used to check remainder.

The program will be as follows:

class Looping

{

public static void main(String args[])

{

int i;

for(i=40;i<=150;i++)

{ //Starting Loop

if(i%7==0)

System.out.println(i);

} //Ending Loop

}

}

Output will be:

42

49

56

63

70

77

84

91

98

105

112

119

126

133

140

147

Check the images attached. (Program + Output)

Attachments:
Answered by Siddharta7
5

class print

{

public static void main(String ar[])

{

int i;

System.out.println(“No. divisible by 7 in between 40 and 150″);

for(i=40;i<=150;i++)

{

if(i%7==0)

System.out.print(i +”,”);

}

}

}

Hope it helped you!

Similar questions