Java Program For Counting Specific Character In Word
Jun 27, 2014
I am trying to make a java program which should count the occurrences of a specific character in a string. I have 1 error - "cannot find method charAt(int)". Here is what I have.
import java.util.Scanner;
public class ch4q5 {
public static void main(String[] args) {
String input ;
String t ;
int c = 0;
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)
I am looking for a way to create a method with the initial state in while loop, which will count the length of each word in a string using I want the output to be something along the lines of:
hello world how are you There are 0 words of length 0 There are 0 words of length 1 There are 0 words of length 2 There are 3 words of length 3 There are 0 words of length 4 There are 2 words of length 5
This is my code so far it sort of does the job but not the way i want it too
import java.util.Scanner; import java.util.StringTokenizer; public class Brown_Matthew_13117002{ public static int count(String s, int len){ int result=0; StringTokenizer st=new StringTokenizer(s,"[ ,;]");
[Code] ....
The output would end up being
hello There are 0 words of lenghth 0 world There are 0 words of lenghth 1 how There are 0 words of lenghth 2 are There are 3 words of lenghth 3 you There are 0 words of lenghth 4
I think I need to use string.split instead of stringtokenizer and the while loop is incorrect it needs to loop equal to the number of letters in the longest word. But how to do either of these ?
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.
How do i write a method in java that will add a <b> or <em> tag to a specific word regardless of case or punctuation for example for "run forest RUN!" adding bold to run would be
<b>run<b> & <b>RUN!<b> public void addTag(String word, String tag) {
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..
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.
I am making a java program that translates English into Pirate. I need working with the Word Pair class. I'm not sure what needs to be passed to the default constructor. And how to do the method that will take the words and pair them. here is my code and the dictionary file
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.util.Scanner; public class PirateTranslator { public static void main(String[] args)
I am looking for java codes to generate a word document based on a word template, basically, I have a word template created and in my local path, the template has a proper format with some fields which will be filled in after java codes ran. The java codes will fetch one record from a table, and open the word template and then fill the fields in the word template, and created a new word document and save it in another folder.
I found this example: [URL] which is similar except it uses xml template instead of word template, how to make it work to change the template from xml to word (docx) template?
I have to write a program that will read a picture and then print out the number of blocks inside it.I have to read the picture as a binary matrix of the size r c (number of rows times number of columns).The blocks are groups of one or more adjacent elements with the value 1.
- Blocks are built exclusively of elements with value 1 -Each element with value 1 is a part of some block -Adjacent elements with value 1 belong to the same molecule.
We only take into account the horizontal and vertical adjacency but not diagonal.
INPUT:
In the first line of the input we have the integers r and c, separated with one space. Then we have the r lines, where each contains s 0's and 1's.The numbers inside the individual lines are NOT separated by spaces.The OUTPUT only print the number of blocks in the picture.
Create a WordCounter class with a constructor that takes a file name as a parameter. The class should have two fields: one for the file name and one for a HashMap to store word count information. The constructor should call a private method, countWords, that reads in the file and counts the word frequencies. The class should contain a get method for each field, as well as a print method that prints out the map in the following format:word:frequency. When printing, the map should be sorted by either the word order or frequency (Hint: see Collections.sort)You should include the sample text file on Blackboard
import java.io.File; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.Scanner; public class WordCounter
I was given the assignment of creating a number to word program for my first college java programming homework.
Here is what I have created so far :
import java.util.*; public class PrintNumberInWord { // saved as "PrintNumberInWord.java" public static void main(String[] args) { int number = 5; Scanner sc = new Scanner (System.in); { System.out.println ("Enter a number"); System.out.println(" "); if (number == 1) {
[Code] .....
The first lines were made for us so we could follow a guideline, however, no matter what I type the command prompt displays 5 to me, I know thats because 5 is defined in the beginning but backspacing 5 causes the program not to work at all, how can I get this program to work properly?
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
I use Eclipse (kepler version, with JDK 7) on MacBook Pro (Lion).I want to overwrite a line printed on my console. I used "" for that. I was expecting the cursor to go to the beginning of the line. Instead, it is going to the next line.
I am trying to write a specific byte sequence to a specific memory location on a removable storage drive. Does Java allow me a way to do this? I know the dangers in accessing memory, but the memory location of the data that will be written will never change.
I created the following hangman program, but it only works for one word file inputs. How can I modify the program to make it work for files with a multiple word phrase?
/**This program is a basic Hangman game. It takes a word or phrase from a file, and then asks the user to guess the letters in it. The program ends when the user inputs 8 wrong guesses. */
import java.util.Scanner; import java.io.*; public class hangman{ public static void main (String[] args) throws FileNotFoundException{ Scanner kb = new Scanner(System.in); String guess;
i'm trying to do a program that memorizes the elements formed by a word and a number. For example, if I write ABB 3, AB 2, ABB -2, ABC 5, ZZ 2 the program will write:
ABB 1 (the result of abb (3-2)) ABC 5 AB 2 ZZ 2
Also, should write:
2 AB ZZ 5 ABC 1 ABB
I've tried to do it with a TreeMap but i don't know how it works.
- from the main class will arrive three variable (String name_used, int level_choose, int level_result)
I have a .txt file with this kind of formatting:
mario 1 1 0 1 0 1 carlo 0 0 0 1 1 0 ...
Where I use 1 and 0 in the main for write if the level (you see that the numbers are always sixr? are egual to six level existing) BEFORE is done correct or wrong
- when in the main a user make a level a feedback coming back from the class level saying if the user made the count correctly or wrong. and i wanna replace the value (1 or 0) in the txt file with the new level result.
So i have all what i need as parameters i think.
name_used to look for the correct line in .txt file with .indexOf level_choosed to go throught the correct index of that line level_result (1 or 2) to be replaced with the existing one
Java Code:
public void salvaRisultati(String name_used, int level_choosed, int result_of_level) throws FileNotFoundException{ } } mh_sh_highlight_all('java');
I created a simple Hangman game. It functions correctly, the only issue is when the file contains a phrase (2 or more words), spaces are not displayed when the program is run. For example, if the phrase was Java Programming Forums.
It would appear as _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _.
I want there to be spaces in between the words. How could I fix this? What would I need to add to my code?
import java.util.Scanner; import java.io.*; public class hangman{ public static void main (String[] args) throws FileNotFoundException{ Scanner kb = new Scanner(System.in); String guess; String guesses = ""; int wrongGuess = 8;