ScholarMatic | 24/7 Homework Help

ScholarMatic Will Help You Write Your Essays and Term Papers

Answered » You can buy a ready-made answer or pick a professional tutor to order an original one.

Do not use any data structures. Do not use methods, basically write the code in the main () method. Do not write OOP.

by | Nov 28, 2023 | computer science

Do not use any data structures. Do not use methods, basically write the code in the main () method.

Do not write OOP.

1.

Modify

the first program you have completed

a)

Prompt the user to input two distinct integers: n1 and n2.

b)

If the user enters the negative number(s), convert it/them to positive number(s).

c)

If n1 is greater than n2, swap them (make sure n1 is smaller than n2).

Then, use

two separate

do…while

loops

to do the following:

d)

Use a

do .. while

loop to output all the numbers divisible by 5 from n1 and n2 inclusive and the sum of

these numbers.

e)

Use a

do .. while

loop to output all the numbers not divisible by 5 from n1 and n2 inclusive and the

average of these numbers.

Then, use

two separate

for

loops

to do the following:

f)

Use a

for

loop to output all the odd numbers between n2 to n1 (large to small) inclusive.

g)

Use a

for

loop to output the table of each even integer and its square between 2 and 16 inclusive.

import java.util.Scanner;

public class Loop {

 public static void main(String[] args) {

  Scanner console = new Scanner(System.in);

  //declare variable

      int n1, n2, t,count,num1,num2, num3, num4;

      double sum1, sum2;

  System.out.println(” Enter 2 distinct integers”);

      System.out.println(“Enter the first number: “);

  n1 = console.nextInt();

      System.out.println(“Enter the second number: “);

  n2 = console.nextInt();

  if (n1 < 0)

   n1 = -1 * n1;

  if (n2 < 0)

   n2 = -1 * n2;

  if (n1 > n2)

      {

   t = n1;

   n1 = n2;

   n2 = t;

  }

  num1 = n1;

  sum1 = 0;

  System.out.print(“Numbers divisible by 5 between “+n1+” and “+n2+” : “);

      while(num1 <=n2)

      {

         if(num1 % 5==0)

         {

    System.out.print(num1 + ” “);

    sum1 = sum1 + num1;

   }

   num1++;

  }

  System.out.println();

  System.out.println(“Sum of these numbers : “+sum1);

  num2 = n1;

  sum2 = 0;

  count =0;

  System.out.print(“Numbers not divisible by 5 between “+n2+” : “);

      while(num2 <= n2)

      {

         if(num2 % 5!=0)

         {

           System.out.print(num2 + ” “);

    sum2 = sum2 + num2;

    count++;

   }

     num2++;

  }

  System.out.println();

  System.out.println(“Average of these numbers : “+(sum2/count));

  // Print

    num3 = n2;

  System.out.print(“Odd numbers between 25 and 4 (large to small )”);

     while(num3 >= n1)

     {

        if(! (num3 % 2==0))

        {

    System.out.print(num3 + ” “);

   }

     num3–;

  }

  System.out.println();

     num4 = 2;

     System.out.print(“Table of each even integer and its square between 2 and 16 : “);

     while(num4 <= 16)

     {

        System.out.println(num4+” t”+Math.pow(num4,2));

   num4 = num4+2;

  }

  System.out.println();

 }

}

ScholarMatic: Explanation & Answer

Your ready answer from a verified tutor is just a click away for as little as $14.99


  

Click Order Now to get 100% Original Answer Customized to your instructions!

HOME TO CERTIFIED WRITERS

Why Place An Order With Us?

  • Certified Editors
  • 24/7 Customer Support
  • Profesional Research
  • Easy to Use System Interface
  • Student Friendly Pricing

Have a similar question?

PLAGIRAISM FREE PAPERS

All papers we provide are well-researched, properly formatted and cited.

TOP QUALITY

All papers we provide are well-researched, properly formatted and cited.

HIGHLY SECURED

All papers we provide are well-researched, properly formatted and cited.

ScholarMatic: Get Started

Assignment Writing Service

Feel safe and secure when placing an order on our portal!
Fruitful cooperation begins with solid guarantees, and we are professional enough to promise perfect results. Let’s get it started!