Write a java program that reads a list of integers and outputs those integers in reverse. The input begins with an integer indicating the number of integers that follow. For coding simplicity, follow each output integer by a comma, including the last one. Assume that the list will always contain fewer than 20 integers.


Ex: If the input is:


5 2 4 6 8 10

the output is:


10,8,6,4,2,

To achieve the above, first read the integers into an array. Then output the array in reverse.

Write A Java Program That Reads A List Of Integers And Outputs Those Integers In Reverse. The Input Begins
Write A Java Program That Reads A List Of Integers And Outputs Those Integers In Reverse. The Input Begins

Answers

Answer 1

Answer:

Explanation:

using namespace std;

#include <iostream>

int Go()

{

 

int N;

int A[20];

 

 

cout << " How many integers do you have ??? :>";

cin >> N;

if (N>20) { N=20; }

 

for (int iLoop=0; iLoop<N; iLoop++)

{

 

 cout << "Input integer # " << (iLoop+1) << " :>";  

  cin >> A[iLoop];  

 

}

 

for (int iLoop=N-1; iLoop>=0; iLoop--)

{

 cout << A[iLoop] << " ";

}

cout << endl;

 

 

}

int main()

{

Go();

}

Answer 2

A Java program that reads a list of integers and outputs them in reverse is written as,

import java.util.Scanner;

public class ReverseList {

   public static void main(String[] args) {

       Scanner scnr = new Scanner(System.in);

       

       // Read the number of integers

       int numIntegers = scnr.nextInt();

       

       // Create an array to store the integers

       int[] integers = new int[numIntegers];

       

       // Read the integers into the array

       for (int i = 0; i < numIntegers; i++) {

           integers[i] = scnr.nextInt();

       }

       

       // Output the integers in reverse order

       for (int i = numIntegers - 1; i >= 0; i--) {

           System.out.print(integers[i]);

           

           // Add comma unless it's the last integer

           if (i > 0) {

               System.out.print(",");

           }

       }

       

       System.out.println(); // Add a new line at the end

   }

}

Given that,

Write a Java program that reads a list of integers and outputs those integers in reverse.

Here, The input begins with an integer indicating the number of integers that follow.

For coding simplicity, follow each output integer by a comma, including the last one.

So, A Java program that reads a list of integers and outputs them in reverse:

import java.util.Scanner;

public class ReverseList {

   public static void main(String[] args) {

       Scanner scnr = new Scanner(System.in);

       

       // Read the number of integers

       int numIntegers = scnr.nextInt();

       

       // Create an array to store the integers

       int[] integers = new int[numIntegers];

       

       // Read the integers into the array

       for (int i = 0; i < numIntegers; i++) {

           integers[i] = scnr.nextInt();

       }

       

       // Output the integers in reverse order

       for (int i = numIntegers - 1; i >= 0; i--) {

           System.out.print(integers[i]);

           

           // Add comma unless it's the last integer

           if (i > 0) {

               System.out.print(",");

           }

       }

       

       System.out.println(); // Add a new line at the end

   }

}

Read more about java programming language at:

brainly.com/question/2266606

#SPJ4


Related Questions

Write a program that removes all non-alpha characters from the given input. Ex: If the input is: -Hello, 1 world$! the output is: Helloworld

Also, this needs to be answered by 11:59 tonight.

Answers

Answer:

Explanation:

The following code is written in Python. It is a function that takes in a string as a parameter, loops through the string and checks if each character is an alpha char. If it is, then it adds it to an output variable and when it is done looping it prints the output variable. A test case has been provided and the output can be seen in the attached image below.

def checkLetters(str):

   output = ''

   for char in str:

       if char.isalpha() == True:

           output += char

   return output

the id selector uses the id attribute of an html element to select a specific element give Example ?​

Answers

Answer:

The id selector selects a particular html element

Explanation:

The id selector is uses the id attribute to select a specific html element. For example, if we have a particular header which is an html element and we want to give it a particular background color, we use the id selector and give it an id attribute in the CSS file. An example of an html header with id = 'blue' is shown below. The style sheet is an internal style sheet.

!doctype html

<html>

<head>

<title>Test</title>

<style>

#blue { background-color: blue;

}

</style>

</head>

<body>

<h1 id = 'blue'>Our holiday</h1>

<p>This is the weekend</p>

</body>

</html>

What order? (function templates) Define a generic function called CheckOrder() that checks if four items are in ascending, neither, or descending order. The function should return -1 if the items are in ascending order, 0 if the items are unordered, and 1 if the items are in descending order. The program reads four items from input and outputs if the items are ordered. The items can be different types, including integers, strings, characters, or doubles. Ex. If the input is:

Answers

Answer:

Explanation:

The following code was written in Java and creates the generic class to allow you to compare any type of data structure. Three different test cases were used using both integers and strings. The first is an ascending list of integers, the second is a descending list of integers, and the third is an unordered list of strings. The output can be seen in the attached image below.

import java.util.Scanner;

class Brainly {

   public static void main(String[] args) {

       Scanner in = new Scanner(System.in);

       System.out.println("Order: " + checkOrder(10, 22, 51, 53));

       System.out.println("Order: " + checkOrder(55, 44, 33, 22));

       System.out.println("Order: " + checkOrder("John", " Gabriel", "Daniela", "Zendaya"));

   }

   public static <E extends Comparable<E>> int checkOrder(E var1, E var2, E var3, E var4) {

       E prevVar = var1;

       if (var2.compareTo(prevVar) > 0) {

           prevVar = var2;

       } else {

           if (var3.compareTo(prevVar) < 0) {

               prevVar = var3;

           } else {

               return 0;

           }

           if (var4.compareTo(prevVar) < 0) {

               return 1;

           }  else {

               return 0;

           }

       }

       if (var3.compareTo(prevVar) > 0) {

           prevVar = var3;

       }

       if (var4.compareTo(prevVar) > 0) {

           return -1;

       }

       return 0;

   }

}

Other Questions
What is space?A. The setting of a work of artB. The place where an artist livedC. The distance between objects helppp plzzz right nowwwwwwww Calculate the average atomic mass for element X.(Please HELP) A rectangular prism has a volume of 60cm^3. What could the length, width andheight be? Explain how you know. "Recall, the formula for the volume of a prismis V=lwh.Can you guys help Write an experiment to show that sunlight is necessary for photosynthesis. Which of these is a sexual stereotype? Existen algunas minoras culturales en tu localidad o en tu regin? Averigua sobre una de ellas yelabora un informe.en tu localidad o en tu regin? 100 avadhapuree men raam aur seeta kee khog vishay par 100 shab men anuched likhey What are the advantages and disadvantages of using crowdsourced social media data during a disaster response The following selected transactions were completed by Amsterdam Supply Co., which sells office supplies primarily to wholesalers and occasionally to retail customers. Also note that the company uses a clearing house to take care of all bank as well as non-bank credit cards used by its customers.Record on page 10 of the journalMar. 2 Sold merchandise on account to Equinox Co., $18,900, terms FOB destination, 1/10, n/30. The cost of the goods sold was $13,300. 3 Sold merchandise for $11,350 plus 6% sales tax to retail cash customers. The cost of the goods sold was $7,000. 4 Sold merchandise on account to Empire Co., $55,400, terms FOB shipping point, n/eom. The cost of the goods sold was $33,200. 5 Sold merchandise for $30,000 plus 6% sales tax to retail customers who used MasterCard. The cost of the goods sold was $19,400. 12 Received check for amount due from Equinox Co. for sale on March 2. 14 Sold merchandise to customers who used American Express cards, $13,700. The cost of the goods sold was $8,350. 16 Sold merchandise on account to Targhee Co., $27,500, terms FOB shipping point, 1/10, n/30. The cost of the goods sold was $16,000. 18 Issued credit memo for $4,800 to Targhee Co. for merchandise returned from sale on March 16. The cost of the merchandise returned was $2,900.Record on page 11 of the journalMar. 19 Sold merchandise on account to Vista Co., $8,250, terms FOB shipping point, 2/10, n/30. Added $75 to the invoice for prepaid freight. The cost of the goods sold was $5,000. 26 Received check for amount due from Targhee Co. for sale on March 16 less credit memo of March 18. 28 Received check for amount due from Vista Co. for sale of March 19. 31 Received check for amount due from Empire Co. for sale of March 4. 31 Paid Fleetwood Delivery Service $5,600 for merchandise delivered during March to customers under shipping terms of FOB destination.Apr. 3 Paid City Bank $940 for service fees for handling MasterCard and American Express sales during March. 15 Paid $6,544 to state sales tax division for taxes owed on sales.Journalize the entries to record the transactions of Amsterdam Supply Co. Refer to the Chart of Accounts for exact wording of account titles.Chart of AccountsCHART OF ACCOUNTSAmsterdam Supply Co.General Ledger ASSETS110 Cash121 Accounts Receivable-Empire Co.122 Accounts Receivable-Equinox Co.123 Accounts Receivable-Targhee Co.124 Accounts Receivable-Vista Co.125 Notes Receivable130 Inventory131 Estimated Returns Inventory140 Office Supplies141 Store Supplies142 Prepaid Insurance180 Land192 Store Equipment193 Accumulated Depreciation-Store Equipment194 Office Equipment195 Accumulated Depreciation-Office Equipment LIABILITIES210 Accounts Payable216 Salaries Payable218 Sales Tax Payable219 Customer Refunds Payable221 Notes Payable EQUITY310 Common Stock311 Retained Earnings312 Dividends313 Income Summary REVENUE410 Sales610 Interest Revenue EXPENSES510 Cost of Goods Sold521 Delivery Expense522 Advertising Expense524 Depreciation Expense-Store Equipment525 Depreciation Expense-Office Equipment526 Salaries Expense531 Rent Expense533 Insurance Expense534 Store Supplies Expense535 Office Supplies Expense536 Credit Card Expense539 Miscellaneous Expense710 Interest ExpenseJournalShaded cells have feedback.Journalize the entries to record the transactions of Amsterdam Supply Co. Refer to the Chart of Accounts for exact wording of account titles.How does grading work?PAGE 10JOURNALACCOUNTING EQUATION Paraphrase this text from the Ellis Island site.Ellis Island doctors were particularly watching for signs of contagious diseases. Incurable diseases included trachoma and tuberculosis and guaranteed a return trip to where the immigrant came from. SCC U of 1 pt 3 of 1 1.2.11 Assigned Media A rectangle has a width of 49 centimeters and a perimeter of 216 centimeters. V The length is cm. Splish Brothers Inc. reported net income of $394000 for the year. During the year, accounts receivable increased by $29000, accounts payable decreased by $12000 and depreciation expense of $61000 was recorded. Net cash provided by operating activities for the year is The question, "What are the distinguishing characteristics of effective leaders?" sparked which approach to the study of leadership? Which of the following is true about an opportunity cost? Multiple Choice they are recorded in the accounting records of the company. is a cost that has already been incurred and can not be changed by any decision. is the potential benefit given up when one alternative is selected over another. should never be considered in decision-making. Please someone help I can not get past this question Two parallel conducting plates are separated by 12.0 cm, and one of them is taken to be at zero volts. (a) What is the magnitude of the electric field strength between them, if the potential 5.6 cm from the zero volt plate is 450 V what type of Literary Devices is this passage and provide an explanation " Only the champion daisy trees were serene. After all, they were part of a rainforest already two thousand years old and scheduled for eternity, so they ignored the men and continued to rock the diamondbacks that slept in their arms. It took the river to persuade them that indeed the world was altered." need this ASAP PLEASE 2(5x-3)=24find what x is? If f(a) is an exponential function where f(-3) = 18 and f(1) = 59, then find thevalue of f(0), to the nearest hundredth.