Question
I need help putting
These in correct order. Java
please rearrange the following code into a working program based on the expected output. HINT: Use JDoodle to help in verifyi
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Wrinkle in Time is not mentioned

It needs to be there in the block where values of other books i.e. Grapes of Wrath, Gone With The Wind are saved in books[0] and books[1].

Below is the code without any change in the question

public class BookArrays {
public static void main(String args[]) {
String[] books = new String[3];
books[0] = "Grapes of Wrath";
books[1] = "Gone With The Wind";
  
int[] title = new int[3];
title[0] = 2;
title[1] = 0;
title[2] = 1;
int z = 0;
int ref;
while(z < 3) {
ref = title[z];
z = z + 1;
System.out.print("books=");
System.out.println(books[ref]);
}
}
}

Output

books=null
books=Grapes of Wrath
books=Gone With The Wind

1 public class BookArrays t 2 public static void main(String args) Stringt] books new String[3j s[]Grapes of Wrath 5 books[1]

Below is the code with adding books[2] also to match the output

public class BookArrays {
public static void main(String args[]) {
String[] books = new String[3];
books[0] = "Grapes of Wrath";
books[1] = "Gone With The Wind";
books[2] = "Wrinkle in Time";
int[] title = new int[3];
title[0] = 2;
title[1] = 0;
title[2] = 1;
int z = 0;
int ref;
while(z < 3) {
ref = title[z];
z = z + 1;
System.out.print("books=");
System.out.println(books[ref]);
}
}
}

Output is

books=Wrinkle in Time
books=Grapes of Wrath
books=Gone With The Wind

1 public class BookArrays f 2 public static void main(String args) String[] books-new String[3] Grapes of Wrath 5 books [1

Add a comment
Know the answer?
Add Answer to:
I need help putting These in correct order. Java please rearrange the following code into a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • please evaluate the following code. this is JAVA a. class Car { public int i =...

    please evaluate the following code. this is JAVA a. class Car { public int i = 3; public Car(int i) { this.i = i; } } ... Car x = new Car(7), y = new Car(5); x = y; y.i = 9; System.out.println(x.i); b. class Driver { public static void main(String[] args) { int[] x = {5, 2, 3, 6, 5}; int n = x.length; for (int j = n-2; j > 0; j--) x[j] = x[j-1]; for (int j...

  • I need a java flowchart for the following code: import java.util.*; public class Main {   ...

    I need a java flowchart for the following code: import java.util.*; public class Main {    public static void main(String[] args) {    Scanner sc=new Scanner(System.in);           System.out.print("Enter the input size: ");        int n=sc.nextInt();        int arr[]=new int[n];        System.out.print("Enter the sequence: ");        for(int i=0;i<n;i++)        arr[i]=sc.nextInt();        if(isConsecutiveFour(arr))        {        System.out.print("yes the array contain consecutive number:");        for(int i=0;i<n;i++)        System.out.print(arr[i]+" ");       ...

  • Help with a question in Java: What is the output from the following program? public class...

    Help with a question in Java: What is the output from the following program? public class Methods2 { public static void main(String[] args) { for (int i = 0; i < 3; i++) { for (int j = 0; j <= i; j++){ System.out.print(fun(i, j) + "\t"); } System.out.println(); } } static long fun(int n, int k) { long p = 1; while (k > 0){ p *= n; } return p; } }

  • Language is Java. Thank you.It is a review test and I will find out the rest...

    Language is Java. Thank you.It is a review test and I will find out the rest if I just know that answers. 1) What is the output of the following code: public class Test public static void main(String] args) [ String s1 new String("Java String s2 new String("Java) System.out.print( (s1 s2)(s1.equals (s2))) A) false false B) true true C) false true D) true false E) None of the above 2) Given the following program: public class Test f public static...

  • I need help with adding comments to my code and I need a uml diagram for...

    I need help with adding comments to my code and I need a uml diagram for it. PLs help.... Zipcodeproject.java package zipcodesproject; import java.util.Scanner; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; public class Zipcodesproject { /** * @param args the command line arguments */ public static void main(String[] args) { Scanner input=new Scanner(System.in); BufferedReader reader; int code; String state,town; ziplist listOFCodes=new ziplist(); try { reader = new BufferedReader(new FileReader("C:UsersJayDesktopzipcodes.txt")); String line = reader.readLine(); while (line != null) { code=Integer.parseInt(line); line =...

  • Online shopping cart (continued) (Java) Hello, I need help with Java to figure this out. In...

    Online shopping cart (continued) (Java) Hello, I need help with Java to figure this out. In my Shopping Cart Manager Class (Bottom Code), I get "Resource leak: 'sc' is never closed." I have tried multiple things and cannot figure it out. Thank you. Online shopping cart (continued) (Java) Hello, I need help with Java to figure this out. In my Shopping Cart Manager Class (Bottom Code), I get "Resource leak: 'sc' is never closed." I have tried multiple things and...

  • I need to write a program in java that reads a text file with a list...

    I need to write a program in java that reads a text file with a list of numbers and sorts them from least to greatest. This is the starter file. import java.util.*; import java.io.*; public class Lab3 { static final int INITIAL_CAPACITY = 5; public static void main( String args[] ) throws Exception { // ALWAYS TEST FOR REQUIRED INPUT FILE NAME ON THE COMMAND LINE if (args.length < 1 ) { System.out.println("\nusage: C:\\> java Lab3 L3input.txt\n"); System.exit(0); } //...

  • This is a java code but I need to understand the logic of how is going...

    This is a java code but I need to understand the logic of how is going to run. Can someone help please. int i = 1; while (i <= 5) { xMethod(i); i++; } System.out.println("i is " + i); } public static void xMethod(int i) { do { if (i % 2 != 0) System.out.print(i + " "); i--; } while (i >= 1); System.out.println();

  • Explain this java code, please. import java.util.Scanner; public class Program11 { public static void main(String[] args)...

    Explain this java code, please. import java.util.Scanner; public class Program11 { public static void main(String[] args) { Scanner stdIn = new Scanner(System.in); final int maxSize = 128; String[] titles = new String[maxSize]; int[] lengths = new int[maxSize]; int numDVDs = 0; String op; op = menu(stdIn); System.out.println(); while (!op.equalsIgnoreCase("q")) { if (op.equalsIgnoreCase("a")) { if (numDVDs < maxSize) numDVDs = addDVD(titles, lengths, numDVDs, stdIn); } else if (op.equalsIgnoreCase("t")) searchByTitle(titles, lengths, numDVDs, stdIn);    else if (op.equalsIgnoreCase("l")) searchByLength(titles, lengths, numDVDs, stdIn); System.out.println('\n');...

  • Here is what I got so far also can anyone help me align the output #include...

    Here is what I got so far also can anyone help me align the output #include <iostream> #include <iomanip> using namespace std; class Person { private: string name;    public: Person() { name = ""; } Person(string name) { this->name = name; } string getName() { return name; } void setName(string name) { this-> name = name; } }; class Publication { private: int pubNumber; string title; Person borrower;    public: static int count; Publication() { title = ""; }...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT