Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Write a for loop to print all elements in courseGrades, following each element with a space (including the last). Print forwards, then backwards. End each loop with a newline. Ex: If courseGrades = {7, 9, 11, 10}, print:
7 9 11 10
10 11 9 7
Hint: Use two for loops. Second loop starts
with i = courseGrades.length - 1.
import java.util.Scanner;
public class CourseGradePrinter {
public static void main (String [ ] args) {
Scanner scnr = new Scanner(System.in);
final int NUM_VALS = 4;
int [ ] courseGrades = new int[NUM_VALS];
int i;
for (i = 0; i < courseGrades.length; ++i) {
courseGrades[i] = scnr.nextInt();
}
/* Your solution goes here */
}
}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 1 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Java - Insect Growtharrow_forwardWrite a for loop to print all elements in courseGrades, following each element with a space (including the last). Print forwards, then backwards. End each loop with a newline. Ex: If courseGrades = {7, 9, 11, 10}, print: 7 9 11 10 10 11 9 7 import java.util.Scanner; public class CourseGradePrinter {public static void main (String [] args) {Scanner scnr = new Scanner(System.in);final int NUM_VALS = 4;int [] courseGrades = new int[NUM_VALS];int i; for (i = 0; i < courseGrades.length; ++i) {courseGrades[i] = scnr.nextInt();} /* Your solution goes here */ P.S. The answer came out wrong the first try 7 9 11 10 10 11 9 7Enterarrow_forwardExecute the following statements over initially empty ArrayList myList one after another (cascade). Explain what was changed after each statement (what did it do?) myList.add("z"); ArrayList content: Your explanation (where this output came from): myList.add(0, "a"); ArrayList content: Your explanation (where this output came from): myList.add("t"); ArrayList content: Your explanation (where this output came from): myList.add(2,"w"); ArrayList content: Your explanation (where this output came from): myList.set(0,"b"); ArrayList content: Your explanation (where this output came from):arrow_forward
- Given positive integer numInsects, write a while loop that prints, then doubles, numInsects each iteration. Print values = 1arrow_forwardAdd each element in origList with the corresponding value in offsetAmount. Print each sum followed by a semicolon (no spaces). Ex: If the input is: 4 5 10 12 2 4 7 3 then output is: 6;9;17;15; import java.util.Scanner; public class ComputeOffset { public static void main(String[] args) {final int NUM_VALS = 4;int[] origList = new int[NUM_VALS];int[] offsetAmount = new int[NUM_VALS];int i;Scanner input = new Scanner(System.in); origList[0] = input.nextInt();origList[1] = input.nextInt();origList[2] = input.nextInt();origList[3] = input.nextInt(); offsetAmount[0] = input.nextInt();offsetAmount[1] = input.nextInt();offsetAmount[2] = input.nextInt();offsetAmount[3] = input.nextInt(); /* Your code goes here */ System.out.println();}}arrow_forwardThe second picture is the code. I want the output of the code to look like picture one. What part do I have to fix? THX!arrow_forward
- Java this piece of my code is not working .....I am trying to add Warship with a type or warship , but I keep getting an error ? //add another WarShip instance to the ArrayList. //use a foreach loop to process the ArrayList and print the data for each ship. //count the number of ships that are not afloat. Return this count to main for printing. //In the shipShow method: the number of ships that are still a Float public static int shipShow(ArrayList<Ship> fleetList) { //from the ArrayList, remove the CargoShip that was declared as type Ship. fleetList.remove(2); //Removing ElFaro form the list // review Type casting instanceof | up casting Ship < Warship , subclass is a object of its parents //add warship USS John Warner - add cast by (Ship) new WarShip Ship warship2 = (Ship) new WarShip("USS John Warner", 2015, true, "attack submarine", "United States"); fleetList.add(warship2); int count= 0; //use a foreach loop to process the ArrayList and print the data for each ship.…arrow_forwardconvert this code to JAVA location = [] size = [] rover = 0 def displayInitialList(location, size): global rover print("FSB# location Size") for i in range(len(location)): print(i," ",location[i]," ",size[i]) if rover<len(size)-1: print("Rover is at ",location[rover+1]) else: print("Rover is at ",location[rover]) def allocateMemory(location,size,blockSize): global rover if rover<len(size): while size[rover]<blockSize: rover+=1 if i==len(size): return False location[rover] += blockSize size[rover] -= blockSize rover+=1 return True else: return False def deallocateMemory(location,size,delLocation,delSize): i=0 while delLocation>location[i]: i+=1 location[i]-=delSize size[i]+=delSize while True: print("1. Define Initital memory\n2. Display initial FSB list\n3. Allocate memory\n4. Deallocate memory\n5. Exit") print("Enter choice: ",end="") choice = int(input()) if…arrow_forwardin Java, please. Please add comments. Thank youarrow_forward
- New JAVA code can only be added between lines 9 and 10, as seen in image.arrow_forwardUse Java pl DataFileWords.txt: lovegentlensslovepeacelovekindnesslovepeaceunderstandingkindnessjoypeaceunderstandingfriendshipgentlenssgoodnesslovepeacegoodnesslovegentlensscontrolunderstandingunderstandinggentlensslovepeacepatiencecontrolkindnessgentlensslovepeacejoygoodnesspeacefriendshipgoodnesskindnesslovepeacegoodnesscontrolpatiencejoygentlensspatiencegentlensspatiencekindnessgoodnessjoygentlenssgentlenssarrow_forwardpackage Q2;import java.io.FileInputStream;import java.io.FileNotFoundException;import java.util.ArrayList;import java.util.Scanner;public class Question2 {public static void main(String[] args) throws FileNotFoundException {/*** Part a* Finish creating an ArrayList called NameList that stores the names in the file Names.txt.*/ArrayList<String> NameList;/*** Part b* Replace null on the right-hand-side of the declaration of the FileInputStream object named inputStream* so that it is initialized correctly to the Names.txt file located in the folder specified in the question description*/FileInputStream inputStream = null;Scanner scnr = new Scanner(inputStream); //Do not modify this line of code/*** Part c* Using a loop and the Scanner object provided, read the names from Names.txt* and store them in NameList created in Part a.*//*** Part d* Reorder the names in the ArrayList so that they appear in reverse alphabetical order.*/// System.out.println("NameList after correct ordering: "…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education