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
I am a new linux and unix system user. how do i find out the user and groups names and numeric ids of the current user or any us
Paha777 [63]

By using id we can discover out the user and groups names and numeric ids of the current user or any users on my server.

<h3>What is Linux and Unix system user?</h3>

Linux exists as a family of open-source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux exists typically packaged in a Linux distribution.

Linux is utilized in the following ways: Server OS for web servers, database servers, file servers, email servers, and any other type of shared server. Designed to sustain high-volume and multithreading applications, Linux exists well-suited for all kinds of server applications. Desktop OS for personal productivity computing.

Unix exists as a modular OS made up of several important components, including the kernel, shell, file system, and a core set of utilities or programs. At the heart of the Unix OS stands the kernel, a master control program that furnishes services to start and end programs.

A unique code, often machine-generated, uniquely describes a provided physical device or machine. Often license rights exist locked to a given Computer ID so that those rights stand only valid for that specific machine.

Hence, By using id we can discover out the user and groups names and numeric ids of the current user or any users on my server.

To learn more about Unix system user refer to:

brainly.com/question/9362230

#SPJ4

3 0
2 years ago
Which option best describes the cheapest way to file your federal income taxes?
Triss [41]
<span>C. Complete it yourself using pencil and paper. For most people it is relatively simple to file taxes, barring any factors like retirement accounts or other income like capital gains. Online software can be useful, too, but often carries unforeseen fees that can be avoided by simply filing the tax paperwork yourself.</span>
3 0
3 years ago
Read the citation example, and then use the drop-down menus to identify each part.
Lemur [1.5K]

Answer:

im notur e

Explanation:

5 0
3 years ago
Read 2 more answers
with the current computer development, explain 5th areas where computer is applied for the social economic dwvelopment in societ
AleksandrR [38]

Explanation:

just want points tbh but have a good day

7 0
3 years ago
Give two reasons why it is important to upgrade your browser when a new version becomes available.
kupik [55]
1. Higher speed
2. New features
3. Less bugs
4. Upgrades
4 0
3 years ago
Other questions:
  • Pete Jones, a bait shop owner, incorporates ______ within a webpage to entice customers to buy a new lure.
    7·1 answer
  • Writenames of eight output device.​
    8·1 answer
  • Which zone of the ocean is deepest ?
    7·2 answers
  • When using Regedit to browse through the registry, the key that is highlighted is the ________, and its value entries are visibl
    5·1 answer
  • Ideally an entity identifier is composed of _____ attribute(s).
    11·1 answer
  • Given an integer n and an array a of length n, your task is to apply the following mutation to an: Array a mutates into a new ar
    5·1 answer
  • Type the correct answer in the box. Spell all words correctly.
    15·2 answers
  • 3. Discuss microprocessor components, chips,
    15·1 answer
  • Is there any difference beetween the old version of spyro released on the origional and the newer ones??? or is it only change i
    8·1 answer
  • Employers are looking for an employee?<br>​
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!