Concept explainers
What is the output of the following code? (You may need to use a calculator.)
const int SIZE = 5;
int time[SIZE] = {1,2, 3, 4, 5),
speed(SIZE) = {18, 4, 27, 52, 100},
dist[SIZE];
for (int count = 0; count < SIZE; count++)
dist[count] = time[count] * speed[count];
for (int count = 0; count < SIZE; count++)
{
cout ≪ time[count] ≪ “”;
cout ≪ speed[count] ≪ “”;
cout ≪ dist[count] ≪ endl;
}
Want to see the full answer?
Check out a sample textbook solutionChapter 7 Solutions
Starting Out with C++ from Control Structures to Objects (9th Edition)
Additional Engineering Textbook Solutions
Computer Science: An Overview (12th Edition)
Problem Solving with C++ (9th Edition)
Concepts Of Programming Languages
Web Development and Design Foundations with HTML5 (9th Edition) (What's New in Computer Science)
Starting Out with Java: From Control Structures through Objects (6th Edition)
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
- THIS IS MEANT TO BE IN JAVA Write a program that reads a list of words. Then, the program outputs those words and their frequencies. The input begins with an integer indicating the number of words that follow. Assume that the list will always contain fewer than 20 words. Ex: If the input is: 5 hey hi Mark hi mark the output is: hey - 1 hi - 2 Mark - 1 hi - 2 mark - 1 Hint: Use two arrays, one array for the strings and one array for the frequencies. Please write the code.arrow_forwardI don't want int i and j in (public static void swap(int[] array, int i, int j)) this part. I want you to do it by writing( public static void swap(int[] array){ Just initialize it somewhere else please. How can you do that?arrow_forwarduse java to solve Create a class MagicSquare that prompts the user for a positive odd integer size, generates a normal magic square of order size, and prints it with numbers right-justified and aligned in evenly-spaced columns. You may assume the numbers in the square are 3 digits or less (i.e. size ≤ 31). However, each space-separated column should have a width equal to the largest integer in the magic square. (See example transcripts below.) To generate the magic square, use the following algorithm: Assign 1 to our initial current position: the bottom row, middle column. Place each successive value (up to size * size) in the first of the following positions that is unoccupied: (1) one space down and to the right, or (2) one space up. Positions wrap around the sides, top and bottom, as shown in the following example transcripts (user input underlined):arrow_forward
- For your convenience, code is provided here:public void paint(Graphics g){ double theta = 0; int ry=(int)(150 + 40*Math.sin(theta)), rx=(int)(150 + 40*Math.cos(theta)); int diameter=80; Calendar c = Calendar.getInstance(); String s; super.paint(g); //setBackground(java.awt.Color.blue); //if(start){ //s = "The start time is: " + c.get(Calendar.HOUR) + ":" + c.get(Calendar.MINUTE) + ":" + c.get(Calendar.SECOND); //g.drawString( s, 300, 300); g.setColor(nowcolor); //g.drawOval(rx, ry, diameter, diameter); for(int i = 0; i < iterations; ++i){ //g.setColor(java.awt.Color.lightGray); g.drawOval(rx, ry, diameter, diameter); theta += (Math.PI/180)*(360/iterations); ry = (int)(150 + 40*Math.sin(theta)); rx = (int)(150 + 40*Math.cos(theta)); //g.setColor(java.awt.Color.red);…arrow_forwardTHIS IS MEANT TO BE IN JAVA So far we've learned variables, branches, loops, and some array. The assignment is: Driving is expensive. Write a program with a car's miles/gallon and gas dollars/gallon (both doubles) as input, and output the gas cost for 20 miles, 75 miles, and 500 miles. Output each floating-point value with two digits after the decimal point, which can be achieved as follows:System.out.printf("%.2f", yourValue); The output ends with a newline. This doesn't make sense to me.... Please show the end result and explain why you added what you added. This is what I have so far: import java.util.Scanner; public class LabProgram {public static void main(String[] args) {}}arrow_forwardWhat is the the output of the following code? int **p;p = new int* [5];for (int i = 0; i < 5; i++)p[i] = new int[3];for (int i = 1; i < 5; i++) for (int j = 0; j < 3; j++)p[i][j] = 2 * i + j;for (int i = 1; i < 5; i++){for (int j = 0; j < 3; j++)cout << p[i][j] << " ";cout << endl;}arrow_forward
- Use the java code below and integrate additional method to: Print the minimum values of each row and of each column. public class ArrayOperations2D {public static int[] findRowMax(int[][] anArray) {int[] max = new int[anArray.length];for (int i = 0; i < anArray.length; i++) {int largest = anArray[i][0];for (int j = 0; j < anArray[i].length; j++) {if (anArray[i][j] > largest) {largest = anArray[i][j];}}max[i] = largest;}return max;}public static int[] findRowSums(int[][] anArray) {int[] rowSums = new int[anArray.length];for (int i = 0; i < anArray.length; i++) {int sum = 0;for (int j = 0; j < anArray[i].length; j++) {sum += anArray[i][j];}rowSums[i] = sum;}return rowSums;}public static int[] findColumnMax(int[][] anArray) {int[] max = new int[anArray[0].length];for (int j = 0; j < anArray[0].length; j++) {int largest = anArray[0][j];for (int i = 0; i < anArray.length; i++) {if (anArray[i][j] > largest) {largest = anArray[i][j];}}max[j] = largest;}return…arrow_forwardThis is the question I am struggling with - Write a program that inserts parentheses, a space, and a dash into a string of 10 user-entered numbers to format it as a phone number. For example, 5153458912 becomes (515) 345-8912. If the user does not enter exactly 10 digits, display an error message. Continue to accept user input until the user enters 999. This is what I am given - import java.util.*; public class PhoneNumberFormat { public static void main(String[] args) { // Write code here } }arrow_forwardPlease use Java and Please follow all directions. Several times I've posted this and the output has to include the names of items, quantity, and sale price. Item #03, Quantity: 2, Price: $12. Something like this but please have it in ascending order of quantity in stock. thank you! 1) Declare and initialize an array that keeps records of 10 items. Each item has a name, quantity in stock, and a sale price. Assign random values to numeric fields of each new item, and give sequential item names to each of them: "Item #01". "Item #02," "Item #03," ... Hint: You need to use the Random class library. 2) Traverse this array and print all the items. 3) Sort the values in this array in ascending order of quantity in stock and print all the items.arrow_forward
- This is what I have so far 2. Too few parameters #include <stdio.h> Void simple(); Int main() { Int n; simple(1,2,3,4,5,6,7,8,9,10,11,12); Return0; } Void simple(int n){ printf(“%d”,n); printf(%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d) } What gets printed? The values 1 and the garbage values get printed. Where do the values come from? The values are some random values generated for the storage part failures like this where we are not allocating values but using them. Why? 1 is printed as per the statement. Garbage values are generated because of not having any argument passed to them to locate a specific location. 3. Too small arrayarrow_forwardTHIS IS MEANT TO BE IN JAVA So far we've learned variables, branches, loops, and some array. I was told that "getting the precise spacing, punctuation, and newlines exactly right is a key point of this assignment. Such precision is an important part of programming." Sites like Zillow get input about house prices from a database and provide nice summaries for readers. Write a program with two inputs, current price and last month's price (both integers). Then, output a summary listing the price, the change since last month, and the estimated monthly mortgage computed as (currentPrice * 0.051) / 12 (Note: Output directly. Do not store in a variable.). I'm confused on how to continue with this assignment. Please show the end result and explain why you added what you added. This is what I have so far: import java.util.Scanner; public class LabProgram {public static void main(String[] args) {Scanner scnr = new Scanner(System.in);int currentPrice; int lastMonthsPrice; currentPrice =…arrow_forwardWrite a method, given a String array, will return a new copy of the array but with all of its elements in lower case. (Use Java) (Hint: You can use the method toLowerCase()) For example, if the method receives the following String array: {"stone", "Bronze", "IRON", "Industrial", "INFOrmation"} It should return a new String array with the following values: {"stone", "bronze", "iron", "industrial", "information"}arrow_forward
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT