I/O Streams :: Insert Space At Proper Place By Breaking Sentence Into Correct Words
Nov 27, 2014
You are given 2 files - "testcase.txt" and "validwords.txt".In testcase.txt, the sentences are written without any space inbetween/for ex: this is a sentence which looks ambigous.You are to insert a space at the proper place by breaking the sentence into correct words, ex o/p: this is a sentence which looks ambigous.validwords.txt contains all valid words (as 1 word per line). If you find a word that does not match, replace it with ####. After correcting
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
I am not very comfortable with Strings in Java. The problem I am facing is, taking a string that contains a sentence and reversing the words. Example would be, "Hi I am Bob" and changing it to "Bob am I Hi". Then returning the String.
My initial thoughts were to change the string into a character array and then manually doing the work with loops and tedious comparison statements. I quickly realized that there must be a better way but I am not very familiar with strings in Java to know what a more sufficient way would be.
Basically the requirements are to take a sentence (string of text) and check to see how many times specific words come up and then add to the counter depending on the word.
But I can not seem to get it to add the instances of the goodwords and badwords.
package Strings; import java.io.*; public class SentimentAnalyser { private static String analyse(String text) { int pw = 0; int nw = 0; String[] searchword = { "bad", "terrible", "good", "awesome" };
This is a program to input a sentence and print the words that start with a vowel.......There is no syntax error but on executing and typing the sentence and pressing enter,I get a error saying :
java.lang.StringIndexOutOfBoundsException: String index out of range: 0 at java.lang.String.charAt(String.java:658) at sentence.main(sentence.java:22)
Write a menu driven program that either accepts words and their meanings, or displays the list of words in lexicographical order (i.e. as in a dictionary). When an entry is to be added to the dictionary you must first enter the word as one string, and then enter the meaning as separate string. Another requirement - from time to time words become obsolete. When this happens, such word must be removed from the dictionary.
Use the JOptionPane class to enter the information.
Use the concept of linked list to carryout this exercise. You will need at minimum the following classes:
- A WordMeaning class that hold the name of a word and its meaning. - A WordMeaningNode class that creates the node of information and its link field. - A WordList class that creates and maintain a linked list of words and their meanings. - A Dictionary class that test your classes.
For the output, the program should produce two scrollable lists:
- The current list of words and their meanings. - The list of the deleted words. You need not list the meanings, just the words.
So far, I have everything coded except for the remove method, and I am not sure how to code that. I coded the add method already, but now I don't know where to begin with the remove method in my WordList class. My classes are below.
WordMeaning Class:
public class WordMeaning { String name; String definition; WordMeaning(String t, String d) { name = t; definition = d;
I'm suppose to read the following code and devise a program that can break the lock.
public class InsecurePasswordLock { private char[] secret; private boolean unlocked; public InsecurePasswordLock() { // secrets are usually 30 to 50 upper case characters long // but here's a hard coded example one secret = "ASECRETTHATYOUWILLNOTGUESSTODAY".toCharArray();
[Code]....
So, I believe that I can try various password lengths until I get a return from open that !=-1. But I'm not sure how to implement this. This is what I have so far to get the length:
public char[] breakLock(InsecurePasswordLock lock) { int checkCount=1; int length=0; while(checkCount!=-1){ for(int i=0;i<=25;i++){ char[] key = new char[i]; if(InsecurePasswordLock.open(key)!=-1){ // I get a fault at this line for calling a static method length=i; checkCount=-1; } } }
I get the error:
Cannot make a static reference to the non-static method open(char[]) from the type InsecurePasswordLock..
How can I keep querying the open method to get my length??
I'm trying to figure out how to read in an integer and break it down into a sequence of individual digits in reverse order. Example: an integer input of 12345 gives an output of54321.
it has first name tab, last name tab, so on I'm saying this because it kept changing format but they are Tabs betwwen each word.
I need to print it in the correct order, so I will need to break this down into objects such as FirstName, LastName,Adress ect. I don't know how to break it into pieces. here is my code thus far:
import java.io.*; import java.util.Scanner; public class Postal {
[Code]....
in which while loop do I add these variables, and could i get a example of how to do one, like first name?
/* * 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 part1; import java.awt.*; import java.applet.*; import java.awt.event.*; import javax.swing.*; class brick {
I have a question about a method I have. In my game, I had a move method to move my player left and right, and originally this method was huge, as it also took care checking collisions and a few other things. I broke it up a bit and put the collisions in their own methods and call them from again another method... Here is an extract which I hope illustrates my point:
private static final double MOVE_SPEED = 0.2; private static final double MAX_MOVE_SPEED = 3.5; private static final double STOP_SPEED = 0.18; private double xPos; private double yPos;
[Code] .....
Something I thought might be a good idea is to check the direction collision when im doing the calculations for that direction:
Then I thought instead i can check it after both of these steps:
if(moveLeft || dx < 0.0) { checkLeft(); }
I guess my question is quite general: How much is acceptable to break up a method? How many chains of method calls is acceptable? Is it ok to call the same method from different nearby places?
why am I not getting a proper shape of "Leftarrow"? The result should look like the following (the system draws the arrow abnormally, so the beginning should a real ARROW:
*
* *
* *
* * * * * * * * *
* *
* *
*
here is the class:
Java Code: public class LeftArrow extends ShapeBase { private int lengthOfTail; private int widthOfArrowHead;
So I need to print out the table of conversions from kilogram to pound and from pounds to kilograms. I think I have done a while loop correctly, but it is hard to actually check it since I do not have proper output format. I have tried also %4.2f format option however could not find the proper position in the print.
public static void main (String[] args){ System.out.printf("%10s%10s | %10s%10s ", "Kilograms", "Pounds", "Kilograms", "Pounds"); System.out.println("---------------------------------------------");
I have a signed certificate from Entrust which I used to sign a DeploymentRuleSet.xml file. I placed the DeploymentRuleSet.jar in the proper location C:WindowsSunJavaDeployment, afterward the java control panel's security tab shows a link to "show the active deployment rule set" which did not exist prior to coping the file to the directory. When I click on the link a new window opens and says "Rule Set not found" ....
Below is a method that is suppose to insert a value inside a stack based on the index. I thought it would be easier to copy the value, if any, that was in the index into the variable holder and replace it with the input value. After in which it would copy the holder value and place it at the top of the stack. (topOfStack variable is what the holder is copying too.)
public void pushExact (int index, String input) { String holder = ""; if (maxSize == 0) { theStack[topOfStack] = input; topOfStack++; } else if (topOfStack + 1 < maxSize) { for (int n= maxSize - 1;n >= 0;n--) {
(5,0) with cost 12 (6,0) with cost 14 (6,1) with cost 15 (6,2) with cost 20 (7,2) with cost 44 (7,3) with cost 52 (7,4) with cost 54 (6,3) with cost 71 (5,3) with cost 74 (4,3) with cost 96
Greatest path is of length 10.
Now, the code that I have works, kind of. Instead of recurring several times at each point, it only recurs once.
So say I'm looking at (1,1). With (1,1) being 57. The area around it looks like this.
97 47 56 35 57 41 89 36 98
Now when I look at it, there are several paths it can take. It can go 57, 97 or 57, 89 or 57, 98. However, I'm pretty sure that it just uses the first one that corresponds with the first if statement that is valid. So I start checking north of the value, then northeast, then east, then southeast, which at southeast is where I find my first greater than value. After it finds it's first valid number, it then continues from that number, instead of checking if there are other longer paths stemming from the original value.
In conjunction with that, you can see that the printout just returns all paths from each value. Which isn't what I want. I need a way to store the longest current path, then check each path after to see if it's longer. If it is, it's replaced, if not, it stays the same.
I've also attached Ass1Q2_test4.txt
import java.util.*; import java.io.*; public class MaxIncreasingSub {
To delete "the" from string and display the new string my input------ the dog required output--------- dog my output-------------------thedog
Code :
import java.util.*; class the { public static void main(String args[]) { Scanner in=new Scanner(System.in); System.out.println("Enter a sentence"); String s=in.nextLine();