Display Contents Of File In Reverse Order - Output To Console
Jun 24, 2014
Create a class that allows the user to select a file and output the contents of the file to the console. Recommend using a text file to display, java files are text files. You may want to put this code in a method to allow you to complete the remainder of this assignment without overwriting your code.
- You should ask the user to enter the full path to your file to make certain you are processing the correct file.
- Modify your code/add a method to display the contents of the file in reverse order. You do not need to reverse the characters on each line but simply output the lines of the file in reverse order.
Hint: read the content of the file into an ArrayList and then traverse the ArrayList.
this is what i go so far.
package classActivity;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
public class Select
{
public static String enterFilePath()
[Code] ....
View Replies
ADVERTISEMENT
Jun 22, 2014
I am having a lot of trouble with this lab. basically I have to make a text processor to read in code put it into a file and output the contents of the input file in alphabetical order one word per line. I have to reference the string varaibles input_filename and output_filename.
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
import java.io.File;
public class TextProcessor {
[Code] ....
these are the guidelines to said lab:
1. In the main method define two Strings called input_filename and output_filename. I will be setting these Strings to my own file names for testing your code, so make sure you get these variable names correct, and that you use them properly in the following steps.
2. Read in the text contents of the file referenced by input_filename.
3. Split the contents of the input text into separate tokens, using whitespace as a delimiter.
4. Lower case the tokens.
5. OPTIONAL: remove punctuation
6. Alphabetize the tokens.
7. Using output_filename, write the alphabetized tokens to an output file, one token per line.
8. Be sure to close file streams - no resource leaks!
9. Use methods to separate functionality in your program where possible
View Replies
View Related
Feb 27, 2014
I am trying to do this assignment but I can't get the needed output.
Create a program that asks the user how many floating point numbers he wants to give. After this the program asks the numbers, stores them in an array and prints the contents of the array in reverse order.
Program is written to a class called ReverseNumbers.
Example output
How many floating point numbers do you want to type: 5
Type in 1. number: 5,4
Type in 2. number: 6
Type in 3. number: 7,2
Type in 4. number: -5
Type in 5. number: 2
Given numbers in reverse order:
2.0
-5.0
7.2
6.0
5.4
Java Code:
import java.util.Scanner;
public class apples {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
double[] numbers;
[Code] .....
View Replies
View Related
Oct 10, 2014
I'm trying to make this code's output display like a sentence, since right now it displays downward and doesn' look right.
public class ReverseOrder {
public static void main(String[] args) {
String phrase = "The rain in Spain falls mainly on the Plain";
char[] phraseArray;
phraseArray = phrase.toCharArray();
for(int i = phraseArray.length - 1; i >= 0; i--){
System.out.println(phraseArray[i]);
}
} // end main
} // end ReverseOrder class
View Replies
View Related
Feb 12, 2015
i need to take a txt file and turn it into a csv(comma seperated value) output on console but where to begin.
View Replies
View Related
May 4, 2015
In the program below I'm trying to read the contents of several .txt files in the same diretory and create a new .txt file containing all of the data from each file. My output is generated in the console however my .text file is blank.
public static void main(String[] args) throws IOException {
String target_dir = "C:Files";
String output = "C:Filesoutput.txt";
File dir = new File(target_dir);
File[] files = dir.listFiles();
[Code] .....
View Replies
View Related
Oct 28, 2014
I have the file test.txt that include:
[Computers]
Keyboard=10
Mouse=5
[Cars]
Lamborghini=6
BMW=3
The [Computers] , [Cars] are Category, Keyboards, Mouse,Lamborghini, BMW, are Descriptors and the numbers are values
I have this code until now.
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import java.util.Map;
public class Descriptor {
[Code] .....
All I want is that my program can read the entire txt file and output in console the Category Descriptors and Value.
Example:
Cars: Lamborghini 6, bmw 3
Computers: Keyboards 10, Mouses 6..
View Replies
View Related
Mar 18, 2014
Write a class named FileDisplay with the following methods:
1.) constructor: the class's constructor should take the name of a fil as an arugment.
2.) displayHead: This method should display only the first five lines of the file's contents
Here is the following code I have made so far
import java.io.*;
public class FileDisplay
{
private String filename;
public FileDisplay(String Filename) throws IOException
[Code] ....
First, in my constructor I have taken in an argument and used that argument to open up an output file. Meanwhile, I'm trying to work n the displayhead method to print out information and to read data to. I haven't opened up my input file yet, but I'm not understand how can I read a print data to an output file. in
public void displayHead()
{FileWriter file=new FileWriter(Filename)}
do I make create another instance of the filewriter class to output data?
In simple words, suppose to I want to display some messages on my output file in the displayhead function. Since I already have opened up the file in the constructor, how do I combine that in this method...
View Replies
View Related
Dec 3, 2014
This is how the for loop works for the row,right?
for(int i=array.length-1;i>=0;i--)
{
}
I want to know how the for loop works for the column?
View Replies
View Related
Oct 9, 2014
This is what I have to do:Write a program that takes a string of someone's name and prints it out last name first. Your program must use pointers, not array subscripts. You may use the available string manipulation functions if you find an opportunity.
Example:
"George Washington"
"Washington, George"
I am not sure how to reverse the name, I have been looking in my textbook and online and cannot figure it out. This is what I have put together so far, it does not run. At the end it says unnecessary return value.
import java.util.*;
import java.util.Scanner;
public class Test {
public static void main ( String [] args ) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter name: ");
String name = sc.nextLine();
String lastname = "";
String firstname = "";
for(int i = 0; i < name.length(); i++) {
if(name.charAt(i) == ' ')
View Replies
View Related
Nov 29, 2012
I want to write an application that inputs a sentence, tokenizes the words with method split and reverse the words (not the letters)...I am stuck at the last part: how to reverse them...should I use the method reverse(); ?
Here is my code..
import java.util.Scanner;
import java.util.StringTokenizer;
public class ReversedWords {
//execute application
public static void main( String [] args) {
//get sentence
[code]....
View Replies
View Related
Apr 3, 2014
Below codes find the character frquency how to print this in reverse order using comparator or else
public static void main(String arr[]) {
String s="bebeao";
Map<Character,Integer> chars=new TreeMap<Character,Integer>();
for(int i=0;i<s.length();i++) {
char x=s.charAt(i);
Integer count=chars.get(x);
if(count==null)
[Code] .....
View Replies
View Related
Apr 10, 2014
Write an application, HiFour that prompt for four names and then prints the greetings, but with the names in reverse order and with punctuation as shown in the example.
Enter four names: Alice Bob Carol Dave
Hi Dave, Carol, Bob, Alice.
View Replies
View Related
Apr 23, 2015
import java.util.Scanner;
public class ReverseOrder {
public static Scanner input = new Scanner(System.in);
public static void main(String[] args){
int[] numbers;
double[] reverse;
numbers = readArray();
reverse = reverseOrder(numbers);
[Code] ....
I have to write a program that takes an order of numbers and print the reverse order of those numbers.
the out put i receive is:
How many numbers do you want to enter?
4
Please enter 4 integers separated by a space:
1 2 3 4
Your numbers in reverse order are:[D@1f96302
View Replies
View Related
Apr 5, 2014
I have a college question ask me to write a class StringRevert which does the following:
-prompting user for an interger n
-creating an array of n string
-repeatedly read character string from user input and store them in the array until end of array is reached or user input -quit(quit should not saved in array)
-print the string from array in reverse order, from last enter to first enter.
-assume user always supplie correct input
This is what I've done so far but how to get it working.
import java.util.Scanner;
public class StringRevert {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("enter value of n: ");
int n1 = in.nextInt();
String[] n = new String[n1];
[Code] ....
View Replies
View Related
Sep 12, 2014
I have the following double linked list and I'm supposed to order it descending (reverse) using the printInReverse() method; since the list orders itself ascending when the numbers are added, how could I order it descending in this method? Here's the code without implementing descending/reversing methods:
package test;
import java.util.Scanner;
public class MyList {
private Scanner userInput;
private Integer selectedOption;
private MyListElement firstElement = null;
private boolean exitRequested = false;
[Code] ....
I tried to declare a previousElement variable but I didn't figure out how I'd do that.
View Replies
View Related
Apr 15, 2014
Write a Java program that asks the user to store 10 numbers in an array. You should then print the array in the order entered and then print in reverse order. However, instead of putting all the information in the main, you should use a class called PrintIt. The PrintIt class should have an instance variable that is an array to hold the numbers. You should have a method that will print the array in the order entered. You will also need a method to print in reverse oder. Then create a tester class that asks the user to enter 10 numbers and puts them in an array.
So far I've got this.
public class printIt {
int i;
int [] numArr = new int [10];
public printIt () {
i = -1;
[Code] .....
Output:
Enter a number:
8
34
Forward:
8
34
Reverse:
34
8
end
what i want as an number is being able to print out 10 numbers but this only lets me do two numbers. Why is that so?
View Replies
View Related
Aug 30, 2014
I need this to print output opposite the way it is. When it reads my file it prints it out like this:
4X^0+3X^1+-2X^2+5X^3+6X^5
But is needs to be this:
6x^5+5x^3+-2x^2+3x^1+4x^0
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Iterator;
import java.util.Set;
[code]....
View Replies
View Related
Mar 10, 2014
I have written a shell script which connects to oracle database and performs operation and returns some output message. Script works fine from command prompt. My requirement is to make it run from a web page which I have accomplished. I am getting the output of shell script on a different web page defined by HTML form action in my jsp file. Everything is working fine.
Below is the part of java class I have written:
=============
String fileName = "build_"+ request.getParameter("region");
String arg1 = request.getParameter("release");
String arg2 = request.getParameter("email");
ProcessBuilder pb = new ProcessBuilder(fileName,arg1,arg2);
Process p = pb.start();
InputStream inputStream = p.getInputStream();
[Code] ....
As shown above, my shell script accepts 2 arguements . User enters arguements in the fields provided which are passed to shell script by processbuilder. Script runs successfully and displays output [ success/error ].
But my problem is , the shell script takes nearly 1 hour to do its job in the database and untill then my web page keeps showing as busy. Whereas in command prompt, shell script displays messages as it runs and thus keeps the end user informed about its progress. However, when called from java it waits untill the shell script completes/terminates and finally displays all the messages at once. I want to know if there is a way to display the shell script output on web page as it continues to run in the background ( child process ).
I tried without the waitFor() function but no luck. It still waits for shell script to exit before displaying any message.
View Replies
View Related
May 2, 2014
how to clear my java output console?
View Replies
View Related
Apr 13, 2014
I am writing a class which formats console output as a table. It displays the type of an entry, the name of an entry, and the data for an entry. I am stuck on a required for loop which appends a tab character to a string, for formatting it as a table. It doesn't seem to be adding any of the tabs and I can't tell what I've done wrong. As far as I can tell the contents of the loop are never reached, and I can't make sense of it.
The ConsoleWriter class that contains the code that is in error...
Java Code:
package frontend;
public class ConsoleWriter {
private static String tabbedData(String data, int min) {
System.out.println(); //for debug
int tabcount = 0;
int len=8*min;
[code]....
View Replies
View Related
Aug 2, 2014
package midtermproject;
import java.util.Scanner; //Using for scanner class
import java.awt.Font; //Using for bold
public class MidtermProject {
/**
* @param args the command line arguments
*/
public static void main(String[] args, String setBoldText) {
[code]....
I need the console to display BOLD for the movie title only. I imported java.awt but I do not know what else or how else to do it. I have looked in my book, online, youtube, yahoo answers and I want to figure this out. I found an answer on here that someone talked about java.awt but did not specific what.
View Replies
View Related
Jul 4, 2014
I have never seen a class defined under another class ....
class pe{
static class pqsort implements Comparator<integer>
public into compare(Integer one,Integer two)
return two-one;
}
}
First I want to know how class pqsort is defined under class pe ....
And how the comparator used in this example is sorting elements in reverse order
View Replies
View Related
May 8, 2014
i am doing a program that allow user to run and execute java language in this commandline.jsp, a servlet execute.java , jsp called get consoleout put.jsp to direct it to commandline.jsp...however there a compilation errors cos i could only get a line of string, and when i run loop in commandline.jsp it will not have the output. i could only run helloworld in it.therefore i need code that i can run multiple line in it. i suspect its the print stream error in execute.java
<!DOCTYPE html>
<html>
<head>
<title>java interpreter</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script src="jquery-linedtextarea.js"></script>
<link href="jquery-linedtextarea.css" type="text/css" rel="stylesheet" />
[code]....
View Replies
View Related
Feb 21, 2015
I have to write a program that calculates the average temperature for a month using parallel arrays (it is mandatory to use a parallel array). I'm new to Java (I'm more familiar with C++) so I get confused with the use of methods. I know how to compute the averages already, I just setting up the parallel arrays. This is what I have so far:
Java Code:
import javax.swing.*;
import java.util.Scanner;
public class Temperature {
public static void main(String[] args) {
String[] day = {"Monday", "Tuesday", "Wednesday",
"Thursday", "Friday", "Saturday", "Sunday"};
int[] temp = new int [7];
[Code] .....
For now I just want to show the contents in my array before I start computing averages.
View Replies
View Related
Jan 22, 2014
I took an example from here on client server sockets: Complete Java Networking Explained with Simple Examples - Go4Expert and placed it in separate classes and had a single main to run it both a server then the client.It seems ok but I cannot have the console outputs sharing the same console.
I start the server first and this takes precedence and the client will not output to console unless I stop the restart the app after commenting out the server startup as its already running, then eclipse gives me 2 consoles I can move between Is it possible to have both client and server share output console?
View Replies
View Related