answer.
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
natima
2 months ago
11

7.7 LAB: Using a while loop countdown Write a program that takes in an integer in the range 10 to 100 as input. Your program sho

uld countdown from that number to 0, printing the count each of each iteration.After ten numbers have been printed to the screen, you should start a newline.The program should stop looping at 0 and not output that value. I would suggest using a counter to count how many items have been printed out and then after 10 items, print a new line character and then reset the counter. important: Your output should use " %3d " for exact spacing and a space before and after each number that is output with newlines in order to test correctly.
Computers and Technology
1 answer:
Natasha_Volkova [1K]2 months ago
3 0

Answer:

The code is implemented in Java

  1. public class Main {
  2.    public static void main(String[] args) {
  3.        int count = 0;
  4.        Scanner stream = new Scanner(System.in);
  5.        System.out.print("Enter a number between 10 and 100: ");
  6.        int num = stream.nextInt();
  7.        while(num > 0){
  8.            if(count % 10!= 0){
  9.                System.out.printf("%3d", num);
  10.            }else{
  11.                System.out.println();
  12.                System.out.printf("%3d", num);
  13.            }
  14.            count++;
  15.            num--;
  16.        }
  17.    }
  18. }

Explanation:

To start, initiate a counter named count and set it to zero (Line 3).

Then, instantiate a Scanner object, requesting the user to enter a number from 10 to 100 (Line 4-6).

Implement a while loop that continues as long as the countdown number remains above zero (Line 8). Then, introduce an if statement to determine if the counter is a multiple of 10. If it is not, display the current num; if it is, start a new line before displaying the current num (Line 9 -14).

After each iteration, increase the count by one and decrease num by one (Line 15 -16).

You might be interested in
Q2 - Square Everything (0.25 points) Write a function called square_all that takes an input called collection that you assume to
zubka84 [1067]
Refer to the explanation Define the function square_all() that receives a list of integers. This function should return a new list containing the square values of all integers found within the provided list. def square_all(num_list): #Initiate an empty list to store results. sq_list = [] #Iterate through the length of the list. for index in range(0, len(num_list)): #Calculate the square of the current value and add it to the result list sq_list. sq_list.append(num_list[index] * num_list[index]) #Return the squared values of all integers in num_list. return sq_list #Declare and initialize a list of integers. intList = [2, 4] #Invoke the square_all() function and pass the above list as an argument. Show the returned list. print(square_all(intList))
4 0
2 months ago
Any software or program that comes in many forms and is designed to disrupt the normal operation of a computer by allowing an un
ivann1987 [1066]
Trojan horse. They arrive disguised.
8 0
2 months ago
Why is computer called versatile machine?
8_murik_8 [964]
The computer is referred to as a versatile machine because of its incredible speed across various domains, making it hard to envision modern life without it.
7 0
2 months ago
Write a program that prompts the user for an integer, then asks the user to enter that many values. Store these values in an arr
Rzqust [1037]

Answer:

//To facilitate user input, the Scanner class is imported

import java.util.Scanner;

//The Solution class is being defined

public class Solution {

   //The main method is declared here, marking the start of program execution

   public static void main(String args[]) {

       

       //A Scanner object named 'scan' is instantiated to gather user input

       Scanner scan = new Scanner(System.in);

       //User is prompted to specify the size of the array

       System.out.print("Enter the range of array: ");

       //The user input is stored in arraySize

       int arraySize = scan.nextInt();

       //Initialization of userArray with the size specified by arraySize

       int[] userArray = new int[arraySize];

       

       //A counter is initialized to track the number of elements entered in the array

       int count = 0;

       //The following while loop will continue until the user finishes inputting the elements of the array

       while (count < arraySize){

           System.out.print("Enter each element of the array: ");

           userArray[count] = scan.nextInt();

           count++;

       }

       

       //A blank line is outputted for better readability

       System.out.println();

       

       //A for loop iterates to print all elements of the array in a single line

       for(int i =0; i <userArray.length; i++){

           System.out.print(userArray[i] + " ");

       }

       

       //Another blank line is printed for clarity

       System.out.println();

       

       //A for loop is utilized to reverse the contents of the array

       for(int i=0; i<userArray.length/2; i++){

           int temp = userArray[i];

           userArray[i] = userArray[userArray.length -i -1];

           userArray[userArray.length -i -1] = temp;

       }

       

       //A for loop prints each element of the reversed array in one line

       for(int i =0; i <userArray.length; i++){

           System.out.print(userArray[i] + " ");

       }

     

   }

}

Explanation:

The program is annotated to provide a thorough explanation.

The for-loop responsible for reversing the array operates by splitting the array into two segments and swapping elements from the first segment with those from the second segment. During each loop, an element from the first segment is temporarily stored in temp variable, and then that element is replaced with the corresponding element from the second segment. Subsequently, the element from the second segment is updated with the value held in temp.

3 0
2 months ago
According to the author, there are five hedging strategies organizations can pursue. One of them is: Select one: a. commit with
zubka84 [1067]

Answer:

The correct choice is option "A": commit with fallback.

Explanation:

The American scholar Alfred A. Marcus (born 1950) discusses in his book "The Future of Technology Management and the Business" (2015) that hedging can serve as a strategy to protect businesses from the rapidly changing landscape brought on by ongoing technological advancements in the market. As per Marcus, firms should adopt five hedging strategies:

  1. Bet on the most likely: focus on the product with the greatest success potential.
  2. Follow a robust approach: invest across numerous products.
  3. Postpone until more clarity is gained: wait for the appropriate moment to respond to market shifts.
  4. Commit with a fallback: adjust according to market conditions.
  5. Strive to shape the future: innovate.
7 0
2 months ago
Other questions:
  • Write a program that takes a date as input and outputs the date's season. The input is a string to represent the month and an in
    13·2 answers
  • A have a string, called "joshs_diary", that is huge (there was a lot of drama in middle school). But I don't want every one to k
    5·1 answer
  • Assume that getPlayer2Move works as specified, regardless of what you wrote in part (a) . You must use getPlayer1Move and getPla
    14·1 answer
  • Consider a load-balancing algorithm that ensures that each queue has approximately the same number of threads, independent of pr
    14·1 answer
  • One form of Intrusion Detection System (IDS) starts operation by generating an alert for every action. Over time, the administra
    5·1 answer
  • Describe a situation involving making a copy of a computer program or an entertainment file of some sort for which you think it
    7·1 answer
  • A wireless network was recently installed in a coffee shop and customer mobile devices are not receiving network configuration i
    12·1 answer
  • What term best describes the grammatical rules for writing proper code? paths syntax hyperlinks declarations
    7·2 answers
  • Write a program that calculates an adult's fat-burning heart rate, which is 70% of 220 minus the person's age. Complete fat_burn
    10·1 answer
  • A bicycle sharing company is developing a multi-tier architecture to track the location of its bicycles during peak operating ho
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!