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
Maslowich
3 years ago
7

Create a program asks a user for an odd positive integer. If the user gives and even number or a number that is negative it prom

pts the user to enter a number again. Once the user enters a number it sums all the odd numbers between 1 and the number entered.
Computers and Technology
1 answer:
KiRa [710]3 years ago
6 0

Answer & Explanation:

//written in java

import java.util.Scanner;

public class Main {

   public static void main(String[] args) {

       // variable for number imput and for the output to

       //to be calculated

       int number, output = 0;

       //a do while loop to first ask for user input

       //and check if its a odd number and a positive integer

       do {

           System.out.println("Please enter a positive odd integer");

           //scanner class to accept user input

           Scanner input = new Scanner(System.in);

           number = input.nextInt();

           //the next line make sure input is a

           // positive integer and also odd

           //number

       } while (number % 2 == 0 || number < 1);

       //for to sum all value of odd numbers between

       //1 and the inputted value

       for (int i = 3; i < number; i = i + 2) {

           output = output + i;

       }

       //print out output

       System.out.println("sums of all the odd numbers between 1 and the " + number + " is " + output);

   }

}

...............................................................................................................................................

Sample of the program output

> Please enter a positive odd integer

< 12

> Please enter a positive odd integer

< 13

> sums of all the odd numbers between 1 and the 13 is 35

You might be interested in
When you call a ____________ method, it executes statements it contains and then returns a value back to the program statement t
Maksim231197 [3]

Answer:

The answer is a VOID method.

Explanation:

A void method is one that simply performs a task and then terminates.

4 0
4 years ago
Read 2 more answers
What is the difference between auto fill and fill handle ?​
lidiya [134]

Answer:

  • Auto fill a software function that automatically completes data (like the data that has been entered previously) without the user needing to type it in full.

  • The Fill Handle is a feature in Excel that fills the data automatically with a specific pattern in your spreadsheet cell.

hope u liked the answer :)

7 0
3 years ago
Hi I need help, This assignment is for Assignment 6 Question 3 in edhesive for computer science. here is the prompt:
miv72 [106K]

Answer: print("THIRD")

for i in range(10):

   for j in range(10-i):

       print(" ", end=" ")

   for j in range(i):

       print("*", end=" ")

   print("")

Explanation:

You're Welcome yall

print("THIRD")

for i in range(10):

   for j in range(10-i):

       print(" ", end=" ")

   for j in range(i):

       print("*", end=" ")

   print("")

6 0
4 years ago
This variable controls the number of times that the loop iterates. A. Counter variable B. Loop control variable C. Running total
Norma-Jean [14]

Answer:

B) Loop control Variable

Explanation:

When programming, A loop control variable is used to control the number of iterations for a program loop. By convention programmers love to call this variable counter, i, j, n etc. The control variable when defined will determine the number of times a loop will execute. See the example bellow in C++ where we use a for loop to print the word "Hello" 5 times

<em>#include <iostream></em>

<em>using namespace std;</em>

<em>int main()</em>

<em>{</em>

<em>  for(int counter = 0; counter<5; counter++){</em>

<em>    cout<<"Hello"<<endl;</em>

<em>  }</em>

<em>    return 0;</em>

<em>}</em>

In this code snippet, the control variable is called counter and the condition is that counter will run from 0 to 4. So we get the world Hello printed five times

8 0
3 years ago
Why are formulas used in spreadsheets?
cluponka [151]

Answer:

The answer to this question is given below in the explanation section.

Explanation:

The correct answer to this question is B.

The formulas in the spreadsheet are used to do the automatic calculation when data is changed in the spreadsheet.

For example, if you add numbers in a column and then get average. you can use sum() and average() formula to calculate the sum and average of numbers in a column. If you will change any number in the column, the calculation for sum and average automatically done. So, the answer to this question is B. i.e.

so that calculations are automatically redone when data is changed.

While the other options are not correct because:

  • To ensure data is entered correctly is done by validation not by using formula.
  • To ensure data is properly formated is done in the formatting section.
  • The error can be easily identified using validation features in excel.

7 0
3 years ago
Other questions:
  • Your bank offers to lend you $114,400 at an 8.5% annual interest rate to start your new business. The terms require you to amort
    11·1 answer
  • What the repeal of online privacy protections means for you?
    8·1 answer
  • What formula would you enter to add the values in cells b4, b5, and b6?
    10·1 answer
  • How will you ensure that all of the network's applications and tcp/ip services also support ipv6?
    10·1 answer
  • I’m turning my Pinterest into a professional account what should be my user name please try to think of a good name and not just
    11·2 answers
  • Write a method that determines the total number of chars in each string of an array.
    12·1 answer
  • Which shortcut key combination will move the cursor to the beginning of the line?
    13·1 answer
  • Which types of files can be used to define Kubernetes manifest files? yaml, json, yaml and text files
    5·1 answer
  • In Word, the mailing list is known as the ​
    12·1 answer
  • Write a function that receives a one-dimensional array of integers and returns a Python tuple with two values - the minimum and
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!