Explanation of Solution
a.
Program to print sum of even numbers between 2 to 100:
//Definition of class Main
class Main
{
//Definition of main method
public static void main(String[] args)
{
//Initialize the value
int evenNum = 0;
//Check the condition using for loop
for (int n = 2; n <= 100; n = n + 2)
{
...Explanation of Solution
b.
Program to print the sum of squares:
//Definition of class Main
class Main
{
//Definition of main method
public static void main(String[] args)
{
//Declare the variables
int SquareSum = 0;
//Check the condition using
for (int i = 1; i <= 100; i++)
...
Explanation of Solution
c.
Program to sum of all odd numbers between “a” and “b”:
//Definition of class Main
class Main
{
//Definition of main method
public static void main(String[] args)
{
//Initialize the variables
int a=10;
int b=50;
int sumOddNum = 0;
//Check the condition using for loop
for (int i = a; i <= b; i++)
{
//Check "i" mod "2" equals to 1
...
Explanation of Solution
d.
Program to print the sum of odd digits:
//Definition of class Main
class Main
{
//Definition of main method
public static void main(String[] args)
{
//Initialize the variables
int num = 23456;
int OddDigits = 0;
//check the condition using while loop
while (num > 0)
{
//Mod the num value by 10
int rem = num % 10;
//Check the condition using "if" statement
if (rem % 2 == 1)
�...
Want to see the full answer?
Check out a sample textbook solutionChapter 6 Solutions
Big Java, Binder Ready Version: Early Objects
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education