Counting The Frequency Of Numbers Inside A Text File

Apr 7, 2014

I have a source code here that counts the frequency of alphabetic characters and non-alphabetic characters (see the source code below).

import java.io.*;
 
public class letterfrequency {
public static void main (String [] args) throws IOException {
File file1 = new File ("letternumberfrequency.txt");
BufferedReader in = new BufferedReader (new FileReader (file1));
 
[Code] ....

But, let's just say that now I have the following characters in the text file, "letternumberfrequency.txt":
71 geese - 83 cars - 58 cows- 64 mooses- 100 ants- 69 bangles- 90 molehills - 87 noses

The numbers inside that text file would be considered as strings, am I right? But I want to extract the numbers so that I can also be able to count their frequency - not as individual digits but as whole numbers (that is how many "71", "83", "58", "64", etc. are there...). Would using "Double.parseDouble ()" work?

View Replies


ADVERTISEMENT

Reading Entire Integer Text File And Putting Inside Array?

Apr 5, 2014

I have an assignment on sorting, i kno i can get the sorting down but im having an issue with inputing the 512 ints in a file into an array. the instructor provided us with a file with 4 equal sets of ints. i tried to make my array of size [scan.nextInt()] and it cuts off the last 21 ints. and skips the first int. how can i get all of the integers in the text file into my array? this is what i have so far. if i hard code the array to size 50000 and then try to print the array it compiles but errors out when running it.

System.out.println("Please Enter text file in this format, XXXXX.txt :");
String file =fileName.nextLine();
Scanner scan = new Scanner(new File(file));
int [] data = new int[scan.nextInt()]; <-------here it skips first int
int count= data.length;
for (int i=0; i<data.length-1;i++) {
data[i]=scan.nextInt();
}
System.out.print(Arrays.toString(data));

rst 4 ints in output are: 501, 257, 390, 478...., supposed to be 492,501,390....and last ints are: ....88, 83, 79, 0 and supposed to be :88 83 79 77 76 72 71 71 66 57 56 48 48 41 33 30 23 23 18 17 15 13 9....it replace last ints with 0. why ? and how do i fix this. attached it the text file

View Replies View Related

Creating Simple Text Editor - Delete Selected Text Inside Text Area

May 13, 2015

This is the code that I wrote but I have two problem with two buttons one of them ... I want to delete the selected text inside the text Area which represented as b[8] and the other button that I want to select parts of the texts which represented as b[0]....

Here is the code..

package KOSAR2;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;

[Code] .....

View Replies View Related

How To Read Numbers And Names From A Text File

Mar 20, 2014

I have a text file containing numbers and names as shown in the example below:

61133128805241Albert Rosenberg
64763645543509Joel
79256337754219Michael Burton

I'm making a program that will read the file and put the numbers in a list of int arrays and names in another list of strings. In my program i created two classes. One will receive the numbers and the other will receive the names. But i only can read the numbers! How can I read everything and separate into two different lists?

try( BufferedReader br = new BufferedReader( new FileReader( jFileChooser1.getSelectedFile().getAbsolutePath() ) ) ) {
hist = new Historic();//Will recieve the array of numbers.
while( br.ready() ) {
int line[] = new int[ 7 ];

[Code] ...

View Replies View Related

Sorting A Text File With Strings And Numbers

Oct 16, 2014

how to sort my text file. So far I have been able to read the text file and print it back out, but I am unsure of how to go about sorting it. Must print the colors (in the order of the rainbow first) and if the colors are the same compare the size (bigger is more important)The values I have to sort are written as such in the text file:

blue 18
blue 10
red 27
yellow 4

public class Rainbow{
private String color;
private int size;
public Rainbow(String color, int size){
this.color = color;
this.size = size;

[code]....

I would know how to sort it if it was supposed to be alphabetical order or there were only numbers, but I can't seem to figure out how to sort it when there are strings and integers

View Replies View Related

Counting Number Of Paragraphs In A Text?

Apr 19, 2014

How do I count the number of paragraphs using a separate method?

import java.util.*;
import java.io.*;
public class WordStats1 {
public static void main(String[] args) {
try {
Scanner input = new Scanner(new FileReader("data.txt"));
PrintWriter output = new PrintWriter(new FileOutputStream(

[code].....

View Replies View Related

Counting Number Of Paragraphs In A Text

Apr 19, 2014

Why my code wont compile the correct number of paragraphs .

import java.util.*;
import java.io.*;
public class WordStats1 {
public static void main(String[] args) {

[Code] ....

View Replies View Related

Placing Numbers Inside Array

Apr 3, 2015

"on each step of the loop you can calculate an entire year as opposed to a single month, otherwise you can calculate monthly, but instead of printing, create an array and fill it up with your solutions, then have a second loop where you add them up by dozens to print yearly values, alternatively, have a counter k that adds up to 12, and two variables for adding up the monthly results, increment these after you calculate the monthly value, and whenever k hits 12, print them and reset to zero. print a final time once you leave the loop. "

int year = loanDurationYears-14;
int[] years= new int[loanDurationYears];
periods = loanDurationYears*12;
for(int i=0;i<1;i++)
{
for(year = 0;year<loanDurationYears;year++)
{
years[year] = year+1;
 
 [code]....

View Replies View Related

Numbers Not Displaying Inside Linked List

Apr 26, 2014

Java Code:

class MyLinkedListH1
{
private class Node
{
private Node link;
private int x;
}
private Node first = null;
public void addFirst(int d)
{
Node newNode = new Node();

[code]...

why this isn't displaying the last digits of the linked it actually isnt displaying any numbers in side the linked list.

View Replies View Related

How To Make A Text File Only Use Lines In A Text File Beginning With A Certain Letter

Mar 15, 2015

I have a program that reads lines of text, but some of the lines of text aren't applicable and break the program. I'd like to put a letter in front of the lines in the .txt file I want to use, such as a #.

I need to make an if loop that'll check for the first letter on the line being #, and use the line in the program if true and skip if false. I'm guessing a boolean variable would be useful here to be true or false depending on the presence of #, but I don't know how to only read the first letter of each line, how can I do this?

View Replies View Related

How To Load XML File Inside Of Java Class File In Netbeans Project

Feb 26, 2015

try {
File configFile= new File("C: Documents and SettingsstudentMy DocumentsNetBeansProjectsCDASsrcconfig.xml ");
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(fXmlFile);
doc.getDocumentElement().normalize();
NodeList nList = doc.getElementsByTagName("config");

[Code] .....

This code is working properly but i have use path like this

File configFile= new File("srcconfig.xml");

Instead of system directory path i have to use path inside of project but i am getting an error-cannot find the specified file...

View Replies View Related

Long Type Output File - Print Prime Numbers Between Given Range Of Numbers

Aug 22, 2014

I tried to create file and write the output of my program in it in java when i use WriteLong then the file does not contain long value, how I create this file my program is to print prime numbers between 500000 to 10000000

public class primenumber {
public static void main(String[] args) {
long start = 5000000;
long end = 10000000;
System.out.println("List of prime numbers between " + start + " and " + end);
for (long i = start; i <= end; i++) {
if (isPrime(i)) {
System.out.println(i);

[Code] ....

View Replies View Related

Pickup Selected Text File And Read Line By Line And Output Text Into Visual Text Pane

Dec 12, 2014

I am checking how to do following task.

01. pickup the selected text file and read the line by line and output the text in to visual text pane.

what i did:.

01. I wrote code that read the text file and output in to jave console/ also some of the interface.

the code read txt file:

Java Code:

String fileName = "C:/Users/lakshan/Desktop/lawyer.txt";
File textFile = new File(fileName);
Scanner in = new Scanner (textFile);
while(in.hasNextLine()){

[code]....

so it will read any text file dynamically and output to the text pane in interface. I think scanner code must be execute after the select the file from the browser and set the scanned result in to variable. then later out put the var as string in some jswing component?

View Replies View Related

Finding The Frequency Of A Pitch

Apr 23, 2014

I'm looking for a library to do FFT stuff, or anything similar. I need to be able to judge the pitch of a note (played on a string instrument).

View Replies View Related

User Enter A File On Text Field And Display Its Hex Representation In Text Area

Apr 17, 2015

I'm supposed to write a GUI application letting the user enter a file on the text field and display its hex representation in a text area and vice versa.

Here's my code:

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package hexconvertor;
import java.util.*;
import java.io.*;
public class HexConvertor extends javax.swing.JFrame {

[Code] .....

It's not doing anything, I don't understand why.

View Replies View Related

Read A Text File And Split The Text Into Tokens

Feb 2, 2014

I am trying to read a text file into Java and split the text into tokens. Eventually I want to be able to count the number of instances of a specific word. However, at this point, when I run the file, all I get is the location of the file rather than the text in the file.

import java.util.*;
import java.io.*;
public class textTest3 {
/**
* Prints the number of words in a given file
*
* @param args
* @throws IOException
*/

[Code]...

View Replies View Related

How To Count Frequency Each Number In Array Occurs

Dec 14, 2014

I'm trying to write a program that counts the number of times each number in an array occurs. In theory I understand how it work, you take the first element in the array, compare it again the rest of the array and any time it occurs in the array you increment a counter by 1. Then move onto the next element A[1] and so on...

This is what I've done so far :

public static void main(String[] args) {
int[] array = {5,6,2,5,2,2,0,1,6};
int count = 0;
for(int i = 0; i <array.length; i++) {
int val = array[i];
for(int j = i+1; j<array.length; j++)

[Code] .....

I think I'm on the right track as it correctly prints out the frequency of the first 3 elements, but I'm definitely going wrong somewhere as it just doesn't do it right after that!

View Replies View Related

How To Modify Class File Inside JAR

Oct 28, 2014

I have to modify my ContainerImpl.java inside a .jar file. My modification is in here: [URL] but I do not know how can I modify it

View Replies View Related

Servlets :: Writing A File Inside WEB-INF?

Nov 29, 2014

I want a servlet to write a file inside WEB-INF folder

I tried these things

File file =new File("feedback.txt");

or

File file =new File("/feedback.txt");

or

File file =new File("WEB-INF/feedback.txt");

View Replies View Related

Obtain Dice As Text Not Numbers

Oct 2, 2014

package dicedemo;
public class DiceDemo {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here

final int Die1_SIDES = 6; // Number of side of dice 1
final int Die2_SIDES = 6; // Number of side of dice 2
// Create two instances of the Die class.

[Code] ....

I need converting the number output to text: example one, two, three, etc.

View Replies View Related

Histogram That Allows To Visually Inspect Frequency Distribution Of A Set Of Values

Apr 4, 2014

Design and implement an application that creates a histogram that allows you to visually inspect the frequency distribution of a set of values . The program should read in an arbitrary number of integers that are in the range 1 to 100 inclusive; then produce a chart similar to the one below that indicates how many input values fell in the range 1 to 10, 11 to 20, and so on. Print one asterisk for each value entered.

No input prompt

Terminate input by typing CTRL/Z (two keys typed at the same time) on a separate input line (use CTRL/D on Linux/UNIX systems)

Use hasNextInt() to terminate your input

Format as below (slightly different from the text example)

Z:dbraffittWeek10> javac Histogram.java

Z:dbraffittWeek10> java Histogram

10 10 10 10 10 20 20 20 20 20 20

20 25 35 45 55 65 75 85 95

ctrl/z

1 - 10 | *****

11 - 20 | *******

21 - 30 | *

31 - 40 | *

41 - 50 | *

51 - 60 | *

61 - 70 | *

71 - 80 | *

81 - 90 | *

91 - 100 | *

What I can not figure out is how to use hasNextInt() to terminate the loop. How to not have an input prompt. How to use ctrl z to terminate the input. Or to make it where it doesn't involve range values like -1.

Java Code:

import java.util.Scanner;
public class Histogram
{
public static void main (String[] args)
{
Scanner scan = new Scanner (System.in);
int [] nums = new int[101];

[Code] ....

View Replies View Related

Cannot Access Class File From Package Inside JAR

Mar 7, 2015

I'm trying to access class file which is inside the package and package is inside the jar file but I can't access that class file inside my source file . All files are on desktop .

View Replies View Related

How To Fetch Values Inside Tag / Node Of XML File

Mar 25, 2015

I need to fetch the values inside the tag/node of an XML file.

The xml.file looks like this,

<numeric_values>
<data cc="100" ln="58">2291</data>
<data cc="100" ln="59">2291</data>
<data cc="105" ln="58">2389</data>
<data cc="105" ln="59">2389</data>
<data cc="110" ln="59">1</data>
<data cc="110" ln="57">1</data>

[Code]...

I need the value of cc and ln.

For example the first line contains cc = 100 and i need to fetch 100 and ln = 58 and i need the value 58.

View Replies View Related

JSP :: Variables / Attributes Scope Inside Tag File

Jul 3, 2014

I have an issue with variables/attributes scope inside a jsp tag file.

In short, I have a tag with an attribute named "id". If the page using my tag has a variable called "id" (maybe coming from the spring model) and I call my tag WITHOUT specifying the id attribute, inside my tag I still can acces to the "id" attribute that was defined in the page but I don't want this behavior; if the tag is called without the "id" attribute then it should defaults to empty/null.

Example:

print.tag
<%@ attribute name="id" required="false" type="java.lang.String" %>
id=${id}
site.jsp

(...)
The id is: ${id} // <- Prints 'X'
<my:print /> <- Prints 'X' ! I want it to not print anything in that case
<my:print id="Y"/> <- Prints 'Y'
(...)

What I want is to have the tag attributes live only in the tag, without having any knowledge of any variable outside of the tag itself. Is it possible?

My current workaround is to remove the "id" attribute, enable dynamic attributes and with a scriptlet search in the dynamic attributes map for the "id" and save it in a variable with a different name (e.g. "__id").

View Replies View Related

How To Modify Text So That It Doesn't Contain Two Equal Numbers

May 3, 2014

I would like to create a program that takes some files and modifies them in this way: The files should contain text formatted in this way:

##############
#various comments#
##############
something{
identifier=1234
anotherIdentifier=1235
anotherOne=12345
//and so on...
}//I need only this
 
#Comments are sometimes made this way
 
somethingAgain{ 
#comments that explains what's below them
I:dentifier:something, I, do, not, need
#see ^that
A:notherIdentifier:boolean
//and so on..
}

And I have to make so that the numbers contained in something{} in all the files don't match. I could ask to make so that the input file is only one, and it is formatted this way:

identifier=1234
anotherIdentifier=1235
anotherOne=12345
//and so on...

but I don't know how to do the rest of the program... That's what I've done (the names of the classes, package etc. are in Italian and there's some useless code that NetBeans prevents me from deleting):

package confronto;
import java.awt.Color;
import java.io.*;
import javax.swing.*;
public class confrontoTesti extends javax.swing.JFrame {
 
[Code] ....

View Replies View Related

Create Histogram That Allow To Visually Inspect Frequency Distribution Of A Set Of Values

Apr 4, 2014

Design and implement an application that creates a histogram that allows you to visually inspect the frequency distribution of a set of values . The program should read in an arbitrary number of integers that are in the range 1 to 100 inclusive; then produce a chart similar to the one below that indicates how many input values fell in the range 1 to 10, 11 to 20, and so on. Print one asterisk for each value entered.

No input prompt
Terminate input by typing CTRL/Z (two keys typed at the same time) on a separate input line (use CTRL/D on Linux/UNIX systems)
Use hasNextInt() to terminate your input
Format as below (slightly different from the text example)
Z:dbraffittWeek10> javac Histogram.java
Z:dbraffittWeek10> java Histogram

[Code] ....

What I can not figure out is how to use hasNextInt() to terminate the loop. How to not have an input prompt. How to use ctrl z to terminate the input. Or to make it where it doesn't involve range values like -1.

import java.util.Scanner;
public class Histogram {
public static void main (String[] args) {
Scanner scan = new Scanner (System.in);
int [] nums = new int[101];
 
[Code] .....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved