1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Rus_ich [418]
3 years ago
8

Write a class that uses DO-WHILE loops to perform the following steps:

Computers and Technology
1 answer:
Murrr4er [49]3 years ago
7 0

Answer:

  1. import java.util.Scanner;
  2. public class Main {
  3.    public static void main(String[] args) {
  4.        Scanner input = new Scanner(System.in);
  5.        int firstNum, secondNum;
  6.        do{
  7.            System.out.print("Input first number: ");
  8.            firstNum = input.nextInt();
  9.            System.out.print("Input second number: ");
  10.            secondNum = input.nextInt();
  11.            for(int i= firstNum; i <= secondNum; i++){
  12.                if(i % 2== 1){
  13.                    System.out.print(i + " ");
  14.                }
  15.            }
  16.            System.out.println();
  17.            int evenSum = 0;
  18.            for(int i= firstNum; i <= secondNum; i++){
  19.                if(i % 2== 0){
  20.                    System.out.print(i + " ");
  21.                    evenSum += i;
  22.                }
  23.            }
  24.            System.out.println();
  25.            System.out.println("Sum of even: " + evenSum);
  26.            System.out.println();
  27.            int squareOddSum = 0;
  28.            for(int i= firstNum; i <= secondNum; i++){
  29.                System.out.println(i + " : " + (i*i) );
  30.                if(i % 2 ==1){
  31.                    squareOddSum += i;
  32.                }
  33.            }
  34.            System.out.println();
  35.            System.out.println("Sum of squared odd number: " + squareOddSum);
  36.        }while(firstNum < secondNum);
  37.    }
  38. }

Explanation:

The solution code is written in Java.

Firstly, we create a Scanner object (Line 6) and use it get user input for first and second number (Line 10-13). We create a for loop and use modulus to check the current number is divisible by 2 and print out the odd number in loop (Line 15-19). We repeat the similar step to print the even number but at the same time, we also add the current number to evenSum variable and print the sum after the for loop (Line 23-33).

Next, we proceed to use another for loop to print out the number and their squares and then accumulate the sum of squares of all odd numbers (Line 36-41).

At last, we print out the sum of squares of odd numbers (Line 43).

In the do while loop condition,  if firstNum is smaller than secondNumber, the loop is ongoing (Line 45).

You might be interested in
Who Has any idea How to code?
kkurt [141]
A bit I guess. I can only do C# though
8 0
3 years ago
Read 2 more answers
What query class will you choose<br> for this query "women are evil"?
nikklg [1K]

Answer:

A) Gibberish or Vague Profane

Explanation:

Hope this helps

7 0
2 years ago
Algorithm<br> Read marks and print letter grade according to that.
Romashka-Z-Leto [24]

Answer:

OKAYYYY

Explanation:

BIJJJJJJJSGJSKWOWJWNWHWHEHIWJAJWJHWHS SJSJBEJEJEJEJE SJEJBEBE

3 0
3 years ago
. ------------- means only one company became historywhich is the acquired
Otrada [13]

Answer:

The correct answer is C. Acquisition means only one company became history which is the acquired company, while the acquiring company remains.

Explanation:

An acquisition occurs when one company or corporation takes control of another (the name itself indicates that the company that acquires the other is the dominant one). Generally, larger companies acquire smaller ones. In such cases, the company acquires a smaller one and establishes itself as the owner.

7 0
4 years ago
Which describes an operating system this is multitasking
xxMikexx [17]
Okay, a Multitasking Operating System(OS) allows you to run many processes (or tasks) <span>"simultaneously".

</span><span>They do not actually run at the same time, of course, since there is only one CPU.
</span>They have to take turns working but they do it really fast (:

Also, if your CPU has multiple cores then you can, run one task on one core, and another on the other core, depending of course on how many cores you CPU has e.g. Quad-Core, Dual-Core, Eight-Core.
5 0
3 years ago
Other questions:
  • Linux distributions overview? information​
    7·1 answer
  • The instructions for the OS provided by application software
    14·2 answers
  • A production house needs an operating system that captures, saves, and generates information within specific time. Which type of
    13·2 answers
  • The clerk ordered three ribbons, 12 markers, and 15 erasers.
    10·1 answer
  • What subsection of the Internet requires specialized browser to access and is frequently used by cyber criminals and underground
    10·1 answer
  • (k + 3)by the power of 3​
    9·1 answer
  • A large number of consecutive IP addresses are available starting at 198.16.0.0. Suppose that four organizations, Able, Baker, C
    11·1 answer
  • Engineers are problem-solvers who use math, science, creativity and other knowledge and skills to solve problems. They use every
    8·2 answers
  • What electronic devices do you use more frequently? And how much time do you use them?
    13·1 answer
  • A(n) ____ is a live internet presentation that supports interactive communications between the presenter and the audience.
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!