Program That Read TXT File And Count Character Occurrence In String
Jan 12, 2014
I wrote a program to read a .txt file and return how many times a, e, s, and t occur in the .txt file. I am getting an error that I do not know how to fix. It says Error: FileNotFoundException cannot be resolved to a type...
import java.util.Scanner;
import java.io.File;
import java.io.IOException;
import java.io.BufferedReader;
public class Count
{
public static void main (String[] args) throws FileNotFoundException {
String phrase; // a string of characters
[Code] ....
View Replies
ADVERTISEMENT
Jan 31, 2014
How to count occurrence of a string in a string array list. I have 800,000 strings in string list..
View Replies
View Related
Dec 27, 2014
public static void main(String[] args) throws FileNotFoundException, IOException{
// TODO code application logic here
FileReader fr = new FileReader("gautam.txt");
BufferedReader br = new BufferedReader(fr);
int line = 0;
int word = 0;
int character = 0;
String s;
while((s=br.readLine())!=null)
[code]...
how to count the character from file
View Replies
View Related
Jun 30, 2014
I have an array with the following characters {'E', 'L','E','P','H','A','N','T','P','O'}
now, I need an array that will store the first array such that only the occurence occurs e.g {'E','L','P','H','A','N','T','O'} Notice that the characters 'E' and 'P' occur twice and as a result were not repeated the second time in the new array.
How would one go about this using the counting elements technique?
I tried this but not sure how to use the counting elements technique.
char [] arr = new char{'E', 'L','E','P','H','A','N','T','P','O'};
char[] bucket = new char[(arr[0] * arr.length)];
for (int i = 0; i < len; i++)
bucket[arr[i]]++;
View Replies
View Related
Jan 29, 2015
I have to write some code to take names from the user and then order them in alphabetical order and then print them out which i have managed to do. However, i can't get it to count the characters in the names that the user enters or count the amount of vowels in the names.
This is the code ive written:
import javax.swing.JOptionPane;
import java.util.Arrays;
String[] names = new String[9];
int i;
names[0] = JOptionPane.showInputDialog("Please enter a name");
names[1] = JOptionPane.showInputDialog("Please enter a name");
[code]....
View Replies
View Related
Apr 26, 2014
I have this program to see the occurrences of a character in a string stored in a text file. My text file has the following contents (as shown below):
Quote
P-P-N-N-L-V
N-R-U-S-R-Q
K-Q-E-L-E-A
A-J-B-G-E-F
F-E-L-Q-R-R
U-F-J-V-I-M
P-I-Q-K-B-K
U-N-L-F-O-B
M-A-N-M-H-O
P-Q-J-D-N-I
G-U-O-D-F-I
Q-M-M-B-C-Q
N-B-I-L-E-J
S-A-T-Q-H-U
C-L-G-U-J-M
R-P-V-M-A-A
C-R-A-V-L-B
M-U-Q-K-M-Q
E-I-C-H-V-J
J-N-N-K-R-P
View Replies
View Related
Mar 7, 2014
Write a program using a while-loop (and a for-loop) that asks the user to enter a string, and then asks the user to enter a character. The program should count and display the number of times that the specified character appears in the string. (So, you will have two separate program codes, one using a while-loop and the other one using a for-loop.)
Example:
Enter a string: "Hello, JAVA is my favorite programming language."
Enter a character: e
The number of times the specified character appears in the string: 3
I don't even know where to begin I've only got this
import java.util.Scanner;
public class letterCounter {
public static void main(String [] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter a string");
String myString = sc.nextLine();
System.out.println("Enter a letter");
String letter = sc.nextLine();
}
}
View Replies
View Related
Feb 28, 2014
(Count occurrence of numbers) Write a program that reads the integers between 1 and 100 and counts the occurrences of each. Assume the input ends with 0. Here is a sample run of the program:
Enter the integers between 1 and 100: 2 5 6 5 4 3 23 43 2 0
2 occurs 2 times
3 occurs 1 time
4 occurs 1 time
5 occurs 2 times
6 occurs 1 time
23 occurs 1 time
43 occurs 1 time
Note that if a number occurs more than one time, the plural word "times" is used in the output.
View Replies
View Related
Jan 21, 2015
I have 2 classes a main one and another class. In the other class I have a method that has:
String gInfo(){
String[] Behavior = {"Sleeping", "Running home", "Studying", "playing pool", "walking to class"};
int rNum = (int) (Math.random() * Behavior.length);
return Behavior[rNum];
}
I call the gInfo() in the main class and run it through a loop 20 times. What I'm trying to do is get it to count the number of times that each behavior happens. and how to get it to work correctly.
View Replies
View Related
Sep 15, 2014
So I need to write a program that reads through a String and counts how many vowels there are and prints them out as it finds them. This is what I have so far:
if (vowel == 'a' || vowel =='e' || vowel =='i' || vowel == 'o' || vowel == 'u'){
numberOfVowels++;
}
The problem is that I can't figure out how to print out the character once it detects it as a vowel.
View Replies
View Related
Jan 12, 2014
for example if the given string is: The world is running java technology?
Ans:
T is =2
h is=2
e is=2
w is=1
n= 4
like wise i need out put of the program?
View Replies
View Related
Apr 26, 2014
I have this program to see the occurrences of a character in a string stored in a text file. My text file has the following contents (as shown below):
P-P-N-N-L-V
N-R-U-S-R-Q
K-Q-E-L-E-A
A-J-B-G-E-F
F-E-L-Q-R-R
U-F-J-V-I-M
P-I-Q-K-B-K
U-N-L-F-O-B
M-A-N-M-H-O
P-Q-J-D-N-I
G-U-O-D-F-I
Q-M-M-B-C-Q
N-B-I-L-E-J
S-A-T-Q-H-U
C-L-G-U-J-M
R-P-V-M-A-A
C-R-A-V-L-B
M-U-Q-K-M-Q
E-I-C-H-V-J
J-N-N-K-R-P
As you notice, each character is seperated by a hyphen (serving as its delimiter). I want to only go through 10 lines in the text, instead of all 20 of them. So, I wrote the program in such a way that I intend to reach into the indices of each character in the text file. Since there are six characters in each line so that means there are 6 indices - and there are 10 lines I only want to go through. So, 6 indices times 10 lines equals 60 indices. Hence, there are only 60 indices I need to go through. In that manner, it's like I have gone through only 10 lines through that way.
It compiled perfectly fine but upon running it, I ran through an error in the black DOS screen that says
"java.lang.ArrayIndexOutofBoundsException: 6 ".
How do I work around that?
The code I wrote is shown below...
import java.io.*;
import java.util.*;
public class hotandcoldclusterdeterminer_test {
public static void main (String args [])throws IOException {
[Code]....
View Replies
View Related
Mar 16, 2014
i need a password program that does the following:
- only shows the character count
- toggles between seeing the actual letters and character count in the text field with a button
i don't know how to update the character count as the user is counting.i read the oracle tutorial, and i have a vague idea that i'm supposed to use Document Listener but i'm quite clueless here.for the second part i'm thinking about using white space for the masking character and unmasking the field.
View Replies
View Related
Nov 17, 2014
So I am saving a file. it is an array of two strings each containing three words. i figured out how to save to a text file and read it back in and put it back into an array. I am using scanner.hasnext and scanner.next and i think that separates the strings into variables using the spaces in the strings. Well for my project i need to do it with a symbol instead of a space
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.Writer;
import java.util.Scanner;
[Code] .....
I put some comments in the read method so you can get exactly what im trying to accomplish....
View Replies
View Related
Jan 27, 2015
So I'm having a problem with the .hasMoreElement() method. I try to read lineOfInput for a file which contains:
Hobbit, Long,t@gmail.com,475-555-4444,3
Long, Hobbit,b@yahoo.com,445-222-5342,2
Hobbit,Long,b@yahoo.com,465-222-5342,2
Help,Yerp,,455-222-2222,4
but when i get to the ,, on the last line I get a NoSuchElementException and the program crashes.
StringTokenizer inputField = new StringTokenizer(lineOfInput, ",");
while(inputField.hasMoreElements()) //for each fields is a line
{
lastName = inputField.nextElement().toString();
firstName = inputField.nextElement().toString();
email = inputField.nextElement().toString();
phoneNumber = inputField.nextElement().toString();
level = Integer.parseInt(inputField.nextElement().toString());
}
View Replies
View Related
Oct 17, 2014
I'm rather new to programming and I'm trying to make a gui program that will allow the user to create text files. They will be prompted to enter what they'd like to save their file as and then they will be allowed to input text to that file . They will also be allowed to open their files to modify or view its contents. So to start things off, I'm making a prototype if you will.. I've been able to save to a file the problem occurs when I try to read/display it.
Main Class:
public class MainActivity {
public static void main(String[] args) {
// Access to other classes
WriteFile writer = new WriteFile();
ReadFile reader = new ReadFile();
[Code] ....
View Replies
View Related
Jul 6, 2014
I have written the code to read the line from file and save first string as word and and remaining string as meaning..
E.g.: innovation a new method, idea, product, etc.
word = innovation
meaning = a new method, idea, product, etc.
In my code there is no error and have a mistake what it is means first assigning word is ok and while saving meaning ..it saves like
{
a a new a new method } like that
Java Code:
import java.io.BufferedReader;
import java.io.FileReader;
public class Dil{
public static void main(String[] arg)throws Exception
{
BufferedReader in;
[Code] ......
View Replies
View Related
Feb 27, 2014
I have a program that is a XML-parser, and it works fine when I'm running it from NetBeans. But when I create a JAR-file and run the very same program, it cannot find the xml file. Consider this small program that addresses my problem:
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import javax.xml.parsers.DocumentBuilder;
[Code] .....
View Replies
View Related
Jul 1, 2014
I need to know why this program is giving me error (illegal start of expression). What must i do to stop the error?
//Read a character from keyboard
class Kbin{
public static void main(String[]args){
throws java.io.IOException{
char ch;
System.out.print( " Press a key followed by ENTER: ");
ch = (char) System.in.read();//read character from keyboard
System.out.println( "Your key is: " + ch);
}
}
}
View Replies
View Related
Dec 3, 2014
The main method will drive your program by doing the following:
-Create an array to hold all the individual golfers and par scores (type is Golfer[ ]).
-Prompt the user for a data file containing the Par scores and the player names and score. The format of the input file should look like
Par, 3, 4, 4, 3, 4, 3, 5, 3, 4
George, 3, 3, 4, 3, 4, 2, 3, 3, 4
Paul, 4, 5, 4, 3, 6, 3, 4, 3, 5
Ringo, 3, 3, 4, 3, 4, 2, 4, 3, 4
John, 4, 4, 4, 3, 4, 2, 5, 3, 4
Your program should read the file contents and store the information in your array of Golfers.
View Replies
View Related
Dec 2, 2014
I am now stuck. I am writing a program that reads information from a data file and runs it through but program. However, I am almost finished with the program, but cannot figure out the last few parts.
public class Storm {
private final double KnotsToMPH = 1.15;
// global user-defined types:
private int beginDate;
private int duration;
private String name;
[Code] .....
I have not attached the data file because it contains a total of 360 lines of hurricane information.
View Replies
View Related
Aug 7, 2014
i am fairly new to java but have made a few projects so i do know most aspects that would allow me to complete the task its just i have been stuck at the same place now for 2 days.The project is to create a java program that can read specific data within a csv file to work out the averages etc. The csv file is a database of different weather stats . an example of the first 12 months of the csv file is below..
[CSV FILE]
year ,month,average rainfall etc
1946 15.70.616108.131.5
1946 28.23.56111.871
1946 38.82932.9 102.9
1946 414.16.3029.2 150.5
1946 513.96060.7 143.6
[code]...
I know that once the data is indexed i can than use a double to find the average of the 12 specific pieces of data and so on. once this is complete i should than be able to transfer the data to a simple graph.
View Replies
View Related
Feb 13, 2015
I am currently trying to count and display all the vowels in a set of given strings and can't seem to figure out what to do. I was able to print the line with the most vowels, but i also need to display them. The code is listed below and the given output.
public class Strings
{
public static void main(String[] args) {
String sentence = "I am currently studing Computer Science."
+ "My name is whatever and I am orginaially from the state of Virginia."
+ "I recenetly separated from the Air Force where I served on the Presidental Honor Guard.";
[Code] ....
The output that i am getting is:
I am currently studying Computer Science .
My name is whatever and I am originally from the state of Virginia.
I recently separated from the Air Force where I served on the Presidential Honor Guard.
The line with most vowels is:
I recently separated from the Air Force where I served on the Presidential Honor Guard.
View Replies
View Related
Feb 14, 2014
I'm trying to use the split method to split a string for a calculator, but it keeps throwing this Exception:
Exception in thread "main" java.util.regex.PatternSyntaxException: Dangling meta character '+' near index 0
+
public class exp {
private static String ques="88+12";
private static String [] splitCalc;
public static void main(String[] args) {
splitCalc = ques.split("+");
for(String s : splitCalc){
System.out.println(s);
}
}
}
View Replies
View Related
Sep 26, 2014
I am trying to remove a character from string as below
public String reomveChar(String str, int n) {
if(0<=n & n<=(str.length()-1)){
//str.charAt(n)
char o=str.charAt(n);
return str.replace("o","");
//a.replace("o","");
}
return null;
}'
what is the best way to remove it.
If i call like
removeChar("hello", 1) i should see hllo.
When there are more than one way to do a challenge in java which one to choose as best way.
What is the criteria to decide one particular way of writing code is best among say 'n' different number of ways.
View Replies
View Related
Mar 7, 2014
String charAt() method returns a particular Character at the specified index in the String.
How is this function implemented internally?. How a particular character can be retrieved from String?.
View Replies
View Related