Question

can some one help me solve this and explain it please Input Format A line indicating...

can some one help me solve this and explain it please

Input Format

A line indicating the size of the array the array on the next line

Constraints

n < 10000

Output Format

One line printing the array in order input (given to you) One line printing the array, followed by its maximum value

Sample Input 0

5
1 3 5 7 9

Sample Output 0

1 3 5 7 9
9 7 5 3 1 9

Contest ends in 29 minutes

Submissions:

0

Max Score:

50

Difficulty:

Medium

Rate This Challenge:

    

More

Current Buffer (saved locally, editable)     

import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;

public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));

int n = Integer.parseInt(bufferedReader.readLine().trim());

String[] myArrayTemp = bufferedReader.readLine().replaceAll("\\s+$", "").split(" ");

List<Integer> myArray = new ArrayList<>();

for (int i = 0; i < n; i++) {
int myArrayItem = Integer.parseInt(myArrayTemp[i]);
myArray.add(myArrayItem);
}

for (int i = 0; i < myArray.size(); i++) {
System.out.print(myArray.get(i));

if (i != myArray.size() - 1) {
System.out.print(" ");
}
}

System.out.println();

// You will now have to print the array in reverse, along with the largest value, on the SAME LINE

// Write your code here

bufferedReader.close();
}
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Hey, I do believe the question is asking something different than what you mentioned in comments; I solved the question according to Output format.

******************************************************************************************************

import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import java.util.concurrent.*;
import java.util.regex.*;
import java.util.Arrays;
import java.util.Collections;

public class Solution {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));

int n = Integer.parseInt(bufferedReader.readLine().trim());

String[] myArrayTemp = bufferedReader.readLine().replaceAll("\\s+$", "").split(" ");

List<Integer> myArray = new ArrayList<>();

for (int i = 0; i < n; i++) {
int myArrayItem = Integer.parseInt(myArrayTemp[i]);
myArray.add(myArrayItem);
}

for (int i = 0; i < myArray.size(); i++) {
System.out.print(myArray.get(i));

if (i != myArray.size() - 1) {
System.out.print(" ");
}
}

System.out.println();

// You will now have to print the array in reverse, along with the largest value, on the SAME LINE

// Write your code here

Arrays.sort(myArrayItem);
for (int i = 0; i < myArray.size(); i++) {
System.out.print(myArray.get(i));
System.out.print(" ");
}
int max = Collections.max(Arrays.asList(myArrayItem));
System.out.println(max);
bufferedReader.close();
}
}

******************************************************************************************************************

Add a comment
Know the answer?
Add Answer to:
can some one help me solve this and explain it please Input Format A line indicating...
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
  • I need help understanding this programming assignment. I do not understand it at all. Someone provided...

    I need help understanding this programming assignment. I do not understand it at all. Someone provided me with the code but when I run the code on eclipse it gives an error. Please explain this assignment to me please. Here is the code: import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Scanner; public class TextEditor { public static List<String> lines = new ArrayList<String>(); public static void main(String[] args) throws IOException { Scanner s = new...

  • 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 =...

  • Public class File {    public String base; //for example, "log" in "log.txt"  &nbs...

    public class File {    public String base; //for example, "log" in "log.txt"    public String extension; //for example, "txt" in "log.txt"    public int size; //in bytes    public int permissions; //explanation in toString public String getExtension() {        return extension;    } public void setExtension(String e) {           if(e == null || e.length() == 0)            extension = "txt";        else            extension = e;    } public class FileCollection {    private File[] files;    /**    * DO NOT MODIFY    * Loads collection from input file    * @param input: name...

  • How to solve this problem by using reverse String and Binary search? Read the input one...

    How to solve this problem by using reverse String and Binary search? Read the input one line at a time and output the current line if and only if it is not a suffix of some previous line. For example, if the some line is "0xdeadbeef" and some subsequent line is "beef", then the subsequent line should not be output. 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.ArrayList; import java.util.List; import java.util.Set; import java.util.TreeSet;...

  • Can anyone help me with this code? I've never worked with insertion sort and I'm having...

    Can anyone help me with this code? I've never worked with insertion sort and I'm having trouble. I posted the instructions and the included code. Thank you! Insertion Sort Given an array of integers, sort the array in ascending/descending order by using Insertion sort. Reference: http://www.algolist.net/Algorithms/Sorting/Insertion_sort Input 4368 92157 Where, • First line represents the type of ordering. • Second line represents the size of the array. • Third line represents the array elements. Output 123456789 + Test Case(s) DriverMain.java...

  • Please help me ONLY for the second method : public static int[] runningGroups(String[] inputFileNames) throws IOException....

    Please help me ONLY for the second method : public static int[] runningGroups(String[] inputFileNames) throws IOException. The second method has an "array of files as a parameter". and return int [ ]. Each element of the return array is the number of group that can get from the first method.    I got an error Exception in thread "main" java.lang.NullPointerException Here my code: import java.io.*; import java.util.ArrayList; import java.util.Scanner; public class RunningGroups { public static void main(String[] args) throws IOException...

  • Below I have my 3 files. I am trying to make a dog array that aggerates...

    Below I have my 3 files. I am trying to make a dog array that aggerates with the human array. I want the users to be able to name the dogs and display the dog array but it isn't working. //Main File import java.util.*; import java.util.Scanner; public class Main {    public static void main(String[] args)    {    System.out.print("There are 5 humans.\n");    array();       }    public static String[] array()    {       //Let the user...

  • Can you help me rearrange my code by incorporating switch I'm not really sure how to...

    Can you help me rearrange my code by incorporating switch I'm not really sure how to do it and it makes the code look cleaner. Can you help me do it but still give the same output? Also kindly add an in-line comment on what changes and rearrangement you've done so I can understand what's going on. import java.util.ArrayList; import java.util.Scanner; public class Bank { /** * Add and read bank information to the user. * @param arg A string,...

  • JAVA: array return types May you please help me fix this coding. Sum is SUPPOSE to...

    JAVA: array return types May you please help me fix this coding. Sum is SUPPOSE to be 1253 import java.util.Scanner; public class Array { public static int sum(int[] arr) { int i; int total = 0; for ( i =0; i < arr.length; ++i) { total = total + arr[i]; } return total; } public static void main(String[] args) { int[] myArray = {45, 22, 18, 89, 82, 79, 15, 69, 100, 55, 48, 72, 16, 98, 57, 75, 44,...

  • Please help me fix my errors. I would like to read and write the text file...

    Please help me fix my errors. I would like to read and write the text file in java. my function part do not have errors. below is my code import java.io.FileInputStream; import java.io.InputStreamReader; import java.io.FileWriter; import java.io.IOException; public class LinkedList {    Node head;    class Node    {        int data;        Node next;       Node(int d)        {            data = d;            next = null;        }    }    void printMiddle()    {        Node slow_ptr...

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