
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
Question
Read the input one line at a time and output the current line if and only if it is larger
than any other line read so far or strictly smaller than the previously outputted line. (Here,
smaller is with respect to the usual order on Strings, as defined by String.compareTo()). you have to use arrylist and cant modify any code under public static void main(string[] args).
example: input
1
3
8
4
5
6
7
9
2
output:
1
3
8
4
9
2
import java.util.*;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Stack;
public class Part2 {
/**
* Your code goes here - see Part0 for an example
* @param r the reader to read from
* @param w the writer to write to
* @throws IOException
*/
public static void doIt(BufferedReader r, PrintWriter w) throws IOException {
/*ArrayList<String> arr = new ArrayList<>();
int count = 0;
String max = "0";
int len = 0;
for (String line = r.readLine(); line != null; line = r.readLine()) {
arr.add(line);
if(arr.get(count).compareTo(max) > 0 ){
max = arr.get(count);
w.println(arr.get(count));
}
if(arr.get(count).length() > 1){
if(arr.size()> 1){
if(arr.get(count).length() >max.length()){
len = arr.get(count).length();
max = arr.get(count);
w.println(arr.get(count));
System.out.println("1: " + arr.get(count));
}
if(arr.get(count).length() == arr.get(count - 1).length()){
if(arr.get(count).length() >= len && arr.get(count).compareTo(max) > 0){
max = arr.get(count);
w.println(arr.get(count));
System.out.println("2: " + arr.get(count));
}
}
if(arr.get(count -1).compareTo(max) == 0 && arr.get(count).compareTo(arr.get(count -1)) < 0){
w.println(arr.get(count));
System.out.println("3: " + arr.get(count));
}
}
}
if(arr.size()> 1){
if(arr.get(count).length() < 2){
if(arr.get(count -1) == max && arr.get(count).compareTo(arr.get(count -1) )< 0){
w.println(arr.get(count));
System.out.println("4: " + arr.get(count));
}
}
}
count++;
}*/
//write your code here
}
/**
* The driver. Open a BufferedReader and a PrintWriter, either from System.in
* and System.out or from filenames specified on the command line, then call doIt.
* @param args
*/
public static void main(String[] args) {
try {
BufferedReader r;
PrintWriter w;
if (args.length == 0) {
r = new BufferedReader(new InputStreamReader(System.in));
w = new PrintWriter(System.out);
} else if (args.length == 1) {
r = new BufferedReader(new FileReader(args[0]));
w = new PrintWriter(System.out);
} else {
r = new BufferedReader(new FileReader(args[0]));
w = new PrintWriter(new FileWriter(args[1]));
}
long start = System.nanoTime();
doIt(r, w);
w.flush();
long stop = System.nanoTime();
System.out.println("Execution time: " + 1e-9 * (stop-start));
} catch (IOException e) {
System.err.println(e);
System.exit(-1);
}
}
}
![}
public static void main(String[] args) {
try {
}
BufferedReader r;
PrintWriter w;
if (args.length == 0) {
r = new BufferedReader (new InputStreamReader (System.in));
w = new PrintWriter(System.out);
} else if (args.length == 1) {
r = new Buffered Reader(new FileReader(args[0]));
w = new PrintWriter(System.out);
} else {
r = new Buffered Reader(new FileReader(args[0]));
w = new PrintWriter(new FileWriter(args[1]));
}
long start = System.nanoTime();
doIt(r, w);
w.flush();
long stop = System.nanoTime();
System.out.println("Execution time: + 1e-9 * (stop-start));
} catch (IOException e) {
System.err.println(e);
System.exit(-1);](https://content.bartleby.com/qna-images/question/e151a9d1-c8c1-4960-9baf-7f2124e2f67a/07e97ce6-2bc7-4912-bb6c-bfc716b6b098/bwcmvnn_thumbnail.png)
Transcribed Image Text:}
public static void main(String[] args) {
try {
}
BufferedReader r;
PrintWriter w;
if (args.length == 0) {
r = new BufferedReader (new InputStreamReader (System.in));
w = new PrintWriter(System.out);
} else if (args.length == 1) {
r = new Buffered Reader(new FileReader(args[0]));
w = new PrintWriter(System.out);
} else {
r = new Buffered Reader(new FileReader(args[0]));
w = new PrintWriter(new FileWriter(args[1]));
}
long start = System.nanoTime();
doIt(r, w);
w.flush();
long stop = System.nanoTime();
System.out.println("Execution time: + 1e-9 * (stop-start));
} catch (IOException e) {
System.err.println(e);
System.exit(-1);
![import java.util.*;
import java.io. Buffered Reader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Stack;
public class Part2 {
* Your code goes here - see Parte for an example
* @param r the reader to read from
* @param w the writer to write to
* @throws IOException
*/
public static void doIt (Buffered Reader r, PrintWriter w) throws IOException {
ArrayList<String> arr = new ArrayList<>();
}
/**
* The driver. Open a Buffered Reader and a PrintWriter, either from System.in
* and System.out or from filenames specified on the command line, then call doIt.
* @param args
*/
Run | Debug
public static void main(String[] args) {
try {
Buffered Reader r;
PrintWriter w;
if (args.length == 0) {
r = new Buffered Reader(new InputStreamReader (System.in));
w = new PrintWriter(System.out);
} else if (args.length == 1) {
r = new Buffered Reader (new FileReader(args[0]));
w = new PrintWriter(System.out);
} else {
r = new BufferedReader(new FileReader(args[0]));
w = new PrintWriter(new FileWriter(args[1]));
}
long start = System.nanoTime();
doIt(r, w);
w.flush();
long stop = System.nanoTime();
System.out.println("Execution time: " + 1e-9 * (stop-start));
} catch (IOException e) {
System.err.println(e);](https://content.bartleby.com/qna-images/question/e151a9d1-c8c1-4960-9baf-7f2124e2f67a/07e97ce6-2bc7-4912-bb6c-bfc716b6b098/y8v8jqs_thumbnail.png)
Transcribed Image Text:import java.util.*;
import java.io. Buffered Reader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Stack;
public class Part2 {
* Your code goes here - see Parte for an example
* @param r the reader to read from
* @param w the writer to write to
* @throws IOException
*/
public static void doIt (Buffered Reader r, PrintWriter w) throws IOException {
ArrayList<String> arr = new ArrayList<>();
}
/**
* The driver. Open a Buffered Reader and a PrintWriter, either from System.in
* and System.out or from filenames specified on the command line, then call doIt.
* @param args
*/
Run | Debug
public static void main(String[] args) {
try {
Buffered Reader r;
PrintWriter w;
if (args.length == 0) {
r = new Buffered Reader(new InputStreamReader (System.in));
w = new PrintWriter(System.out);
} else if (args.length == 1) {
r = new Buffered Reader (new FileReader(args[0]));
w = new PrintWriter(System.out);
} else {
r = new BufferedReader(new FileReader(args[0]));
w = new PrintWriter(new FileWriter(args[1]));
}
long start = System.nanoTime();
doIt(r, w);
w.flush();
long stop = System.nanoTime();
System.out.println("Execution time: " + 1e-9 * (stop-start));
} catch (IOException e) {
System.err.println(e);
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by stepSolved in 3 steps

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
- In Java pleasearrow_forwardGenerate a list of 10 random numbers with values between 1 and 20, and submit the first 10 numbers as an answer to this question. (Use any random number generator). For the purpose of using them in the next questions, call these numbers A, B, C, D, . . . J Convert Aπ/B into degrees. Find the result ofa. Degrees = (A × B × C) + 180 mod 180; this is the remainder after dividing (A × B × C) + 180 by 180 b. Convert Degrees into radians, and put the answer in π notation. Calculate the measurements of the acute angles of a right triangle whose sides measure A, B, C units. Build a matrix, M, of random numbers as follows: A B C D E F G H I What is MT? Find the inverse of M, showing the steps. What is the result of M * M−1? Let V = [A B C] and W = [ D E F]. In the textbook, the dot product V • W involves an angle, alpha (α). How do you calculate alpha for this example? Let V = [A B C]. Find the cross product V • V. What can you conclude from this…arrow_forwardPlease help me fix this program. It is constantly saying I have duplicates of class main and many more Main. Java is below as well as my gui which is the photos (the gui is my problem) import java.util.*; public class Main { //Inputs a one character string and returns True if the character is a letter (i.e. a to z or A to Z). Returns false if it is not. A function to check that the password or encryption key is valid. public static boolean isALetter(char letter){ if( (letter >= 'a' && letter = 'A' && letter =-32767 && encryptKeyarrow_forward
- Invoking time.time() returns the elapsed time in seconds since midnight of January 1, 1970. Write a program that displays the date and time. Here is a sample run: Current date and time is May 16, 2012 10:34:23arrow_forwardNeed help with 8,9, and 10 if possible. Java Codingarrow_forward1. Divisors: In a class Divisors.java, read in a maximum integer n and use nested loops to print a list of divisors for each of 1 through n as shown in the following transcript. Sample transcript (input underlined): Largest integer? 100 1: 1 2: 1 2 3: 1 3 4: 1 2 4 95: 1 5 19 95 96: 1 2 3 4 6 8 12 16 24 32 48 96 97: 1 97 98: 1 2 7 14 49 98 99: 1 3 9 11 33 99 100: 1 2 4 5 10 20 25 50 100arrow_forward
- This is the debugging problem. This is the question - The files provided in the code editor to the right contain syntax and/or logic errors. In each case, determine and fix the problem, remove all syntax and coding errors, and run the program to ensure it works properly. This is the code given - // DebugFive4.java // Outputs highest of four numbers import java.util.*; public class DebugFive4 { public static void main (String args[]) { Scanner input = new Scanner(System.in); int one, two, three, four; String str, output; System.out.println("Enter an integer"); str = input.next(); one = Integer.parseInt(str); System.out.println("Enter an integer"); str = input.next(); two = Integer.parseInt(str); System.out.println("Enter an integer"); str = input.next(); three = Integer.parseInt(str); System.out.println("Enter an integer"); str = input.next(); four = Integer.parseInt(str); if(one…arrow_forwardpublic class utils { * Modify the method below. The method below, myMethod, will be called from a testing function in VPL. * write one line of Java code inside the method that adds one string * to another. It will look something like this: * Assume that 1. String theInput is 2. string mystring is ceorge неllo, пу nane is * we want to update mystring so that it is неllo, пу nane is Ceorge */ public static string mymethod(string theInput){ System.out.println("This method combines two strings."); Systen.out.println("we combined two strings to make mystring); return mystring;arrow_forwardFor Java Write code for an if-else block that checks separates integers into the following categories: An integer less than 0, An integer greater than 0 and less than or equal to 10, An integer greater than 10 that is even, and an integer greater than 10 that is odd. Have each category print out a different statement. What are some ways you can make your code more efficient when using if-else blocks?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