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();
}
}
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();
}
}
******************************************************************************************************************
can some one help me solve this and explain it please Input Format A line indicating...
please help. About java tcp. this is what i have so far. how to convert input value into ASCII sequence For example the message: “Hello World” would become “Ifmmp!Xpsme”For example the message: “Hello World” would become “Ifmmp!Xpsme”in server.java. Client.java: import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintStream; import java.net.Socket; import java.net.SocketTimeoutException; public class Client { public static void main(String[] args) throws IOException { Socket client = new Socket("127.0.0.1", 20006); client.setSoTimeout(10000); BufferedReader input = new BufferedReader(new InputStreamReader(System.in)); PrintStream out...
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...
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;...
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" 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...
Can someone please help me? I'm having trouble with this assignment and have been stuck trying to figure it out for over an hour. Here's the assignment details below: For this assignment, you will develop "starter" code. After you finish, your code should access an existing text file that you have created, create an input stream, read the contents of the text flie, sort and store the contents of the text file into an ArrayList, then write the sorted contents...
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.
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 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 to make it look cleaner 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, double and int array containing * the command line arguments. * @exception Any exception * @return an arraylsit of...