Swap The Word?
Jul 8, 2014i want to swap the word. how could i be able to swap..
for example:-
I/P:-
i want to be a java developer
O/P:-
developer a be to java want
means swap first and last word and all alternate word.
i want to swap the word. how could i be able to swap..
for example:-
I/P:-
i want to be a java developer
O/P:-
developer a be to java want
means swap first and last word and all alternate word.
so I have this matrix
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
If the user for example enter the number 2 for index I need to swap the matrix from this index two lines with two line so this is the result what I need
1 2 5 6
3 4 7 8
9 10 13 14
11 12 15 16
So as of right now, I'm trying to swap my bar arrays and repaint it. For now, I'm using the index 5 and swapping it with index 23. When I click the shuffle button, It swaps, but the highest bar still remains the same.
Here's my code.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
public class AssortedAssortmentsOfSorts extends JFrame
[Code] ......
I have built a binary tree, from a file. In each node, I am storing each word as a string, and an int frequency for each time the word occurs. For the assignment, I need to find how many words occur only once in the file. I wrote the program, but for some reason I am getting a number different from what my professor is expecting.
As far as I know, this file has loaded into the tree correctly, because all of my other answers in the assignment are correct. What am I doing wrong?
public void findUnique() {
System.out.println("There are " + findUniqueWords(root, 0) + " unique words.");
}
private int findUniqueWords(Node subTree, int uniqueCount) {
// Base Case: At the end of the branch
if(subTree == null){
return uniqueCount;
[Code] ....
The intentions of this program is to prompt a user to enter a file name, and then reads the file. The program will prompt the user to enter a word that needs to be corrected. So lets say I have a text file containing "My name is OP and I Like goind to the Park!" I want to change "goind" to "going",
Now, my second method "isSimilar" executes a similar word with more than one same letter and same length, but I dont know how to execute that whole thing in my third method "correctThisLine" . How I can call that isSimilar method and read in that text file and change that word into that?
import java.util.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class WahidMuhammadA3Q2{
String fileName = "AutoCorrectMe.txt";
public static void main (String [] args){
[Code] ....
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?
Here's My Code.
package bin;
import java.util.Scanner;
public class AppletMain{
public static void main(String[] args){
Scanner oneinput = new Scanner(System.in);
String one;
[Code] ....
I am trying to get it to compare the word I type in to the set word in the object 'secretword'. I have tried everything from equal to == to compareTo, I even created a two hundred line program to do this SIMPLE problem.
import java.io.*;
import java.util.Random;
import java.util.Scanner;
public class WordGame
{
public static void main(String[] args) throws IOException
{
final int RANDOM_LETTERS_COUNT = 10;
final int TRIALS = 10;
int score = 0;
[Code] ....
i have completed a code in java so that it can read spaces in a line but when i run it if i put Line 1 test test for example it will print : [ 3] spaces in Line1 test test what i want to print is [ 3] spaces in "Line1 test test" so the diferences is at " Is there any possible thing that i can do?
class Main
{
public static void main( String args[] )
{
System.out.print( "#Enter text : " );
String text = BIO.getString();
while ( ! text.equals( "END" ) )
{
[Code]...
Okay, so the assignment was creating a word search for the given array. I've created all the code necessary, but I've ran into trouble. This problem occurs with the Up-Forward, Up-Backward, Down-Forward, and Down-Backward sections. If I only set one of these to run, it works. But if I have all 4 set at the same time, it errors out on the first one that runs.
public class P_WordSearch {
public static void main(String[] args) {
char[][] puzzle = {
{'B','O','O','G','S','R','O','W','I','N','G'},
{'E','B','L','G','N','I','M','M','I','W','S'},
{'L','C','E','A','T','I','P','U','P','I','S'},
{'C','M','I','N','C','A','X','Y','O','S','N'},
[Code] ....
I'm trying to use regex to find a word containing the substring "cat." I'm not sure why this isn't working?
String match = "^ cat$";
So the exercise I'm working on says to have the user enter their name and the program will output their name with the last name in all caps. i made it work BUT the only way i could figure it out was to ask for the first and last names separately creating two strings rather than one.
Of course I want to make it work how it's supposed to (with one string) so that I'm learning. I'm just having trouble conceptualizing how exactly (with varying lengths of names) to tell the program to only capitalize the second word... at first I thought create a substring beginning with the first letter of the last name and ending with the last...but again, therein lies the issue of varying name lengths.
is there a way to create a substring that beginIndex's at the first "space"? then i could just leave the endIndex parameter empty and it would take the whole word into a new string. and from there utilize toUpperCase to the new string?
Here's my code asking for the first and last names separately.
import java.util.Scanner;
class nameEcho {
public static void main ( String [] args ) {
Scanner scan = new Scanner( System.in );
String first;
String last;
[Code] .....
How to delete word "kumar" from sentence
import java.util.*;
class kumar
{
public static void main(String args[]) {
Scanner in=new Scanner(System.in);
System.out.println("Enter a sentence");
String s=in.nextLine();
s=s=" ";
[Code] ....
I do not get any output nor any error....
I was tasked with building a program that, when is given a string by the user, takes it and prints it out as a rectangle. For example, if the user types in "COMPUTER", the output would be:
COMPUTER
OMPUTERC
MPUTERCO
PUTERCOM
UTERCOMP
TERCOMPU
ERCOMPUT
RCOMPUTE
So far, I have created 2 separate strings, and have gotten the output to look like:
COMPUTER
OMPUTERC
OMPUTERO
OMPUTERO
OMPUTERO
OMPUTERO
OMPUTERO
OMPUTERO
OMPUTERO
So, it works once, but then it doesn't work again. Here is my code:
i was tasked with building a program that, when is given a string by the user, takes it and prints it out as a rectangle. For example, if the user types in "COMPUTER", the output would be:
COMPUTER
OMPUTERC
MPUTERCO
PUTERCOM
UTERCOMP
TERCOMPU
ERCOMPUT
RCOMPUTE
So far, I have created 2 separate strings, and have gotten the output to look like:
COMPUTER
OMPUTERC
OMPUTERO
OMPUTERO
OMPUTERO
OMPUTERO
OMPUTERO
OMPUTERO
OMPUTERO
So, it works once, but then it doesn't work again. Here is my code:
import java.util.Scanner;
public class WordRectangle {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Scanner userInput = new Scanner (System.in);
[code]....
LinkedHashSet=Linked + Hash +Set
In linkedHashSet are the elements stored according to the insertion order or according to the hash value. If the elements are stored according to the insertion order then why is it not named as LinkedSet instead of LinkedHashSet? Why is the word hash used in LinkedHashSet?
I want to write a program to convert word document into excel output..
Is any API available?..
I'm very new to Java, and I'm writing a code to search a string to see how many times the word "dog" is found in it. I'm not sure if this is error-free or the most efficient, but I'd like to keep it simple.
public void run()
{
String input = new String("The Dogman was no ordinary dog, nor man, but rather a peculiar dog-like man who barked like a dog, and panted like a dog, he even ate like a dog. He owned a dog named Doglips, and interestingly enough, his favorite food was hotdogs.");
println(input);
int index = -1;
int count = 0;
print("Counting dogs:");
inputarray = input.split(" ");
[Code] .....
I recently have tryed to make a java code that reads words and say if its palindrome or not. I want to fix two things but unfortunately i can't do it on my own.
1st thing that i want fix is that when i run the code i have to press 2x times enter..and i dont know why?(i want one time to press it when i write the text)
2nd thing that i want to fix is that when you run it you can put as many words as you can..only when you write "END" the code must ends.
So unfortunately my code runs only for 1 time.(one word)
My code:
class test {
public static void main(String args[]) {
System.out.print( "#Enter text : " );
String text = BIO.getString();
String reverse = BIO.getString();
int length = text.length();
[Code] .....
What I need to do is ask the user to input some text and then turn it into pig latin. I am confused on how to select each word from the string to determine if it ends in a way or ay. I am to assume that the letters are all lowercase and the text ends with a period.
import java.util.Scanner;
public class Trial
{
public static void main(String [ ] args)
{
Scanner input = new Scanner(System.in);
[code]....
I am in an intro programming class and we got assigned a problem for creating a super class with about a dozen sub classes for generating a random word(via WordGetter class) and then comparing that word to a variety of different patterns(like: does the word contain "re"). We were given the super class which looks like this...
public class Pattern {
public boolean matches(String text) {
return true;
}
public String toString() {
return "(TRUE)";
[code]...
and from this class, we have to write subclasses that override those three methods. I am struggling to understand inheritance and I am not really sure where to even start. Here is the instructions for the first sub class we need to write...
"CONTAINS" SUBCLASS
Constructor: The constructor accepts a String named ‘letters’.
Matches: This pattern matches any text that contains at least one occurrence of each ‘letter’.
toString: produces the text “(CONTAINS <LETTERS>)” where <LETTERS> is the ‘letters’ string.
getLetters(): this method must return letters.
equals(Object): careful on this one. Two Contains are equal if they have the same letters (order is not relevant).
(Example):
Pattern p = new Contains(“re”);
boolean f1 = p.matches(“renew”); // f1 is true
boolean f2 = p.matches(“zoo”); // f2 is false
String s = p.toString(); // s is “(CONTAINS re)”
boolean f3 = p.equals(new Contains(“er”)); // f3 is true.. really..
I generated random numbers from 1 to 13 and I want the numbers 11 12 13 and 1 to be output as jack queen king and ace respectively.
View Replies View RelatedBelow is my first ever code. I bolded where i am getting a syntax error. Why am i getting an error here if i assigned that word to a string?
public class BeerBottleTest {
public static void main(String[] args) {
int beerNum = 99;
String bottle = "bottles";
while (beerNum > 0) {
if (beerNum == 1) {
bottle = "bottle"; }
[Code] ....
I am creating a user friendly program that allows the user to adjust the dimensions of an oval (painted onto a window) via a 'slider' Everything is fine for the most part, except in the main code- when I tried coding for a window object for some reason java didn't recognize the type (that is, I used the keyword TheWindow and java didn't recognize it) the following is the full code set across 2 classes, but I think the problem is centered around the main class.
package javaIntermediate;
import java.awt.*;
import javax.swing.*;
//NOTE: this is 1 out of 3
[Code]......
I was asked to create a word pyramid program using recursion. I understand the concept of recursion (i.e. a method calling itself with the problem it is solving getting simpler and simpler each time) but I am having issues writing the program. Here is my code:
public static void main(String[] args) {
//This program will create a word pyramid by using a recursive algorithm.
//For example, the output of "DOGGY" should be:
//DOGGY
//OGG
//G
//This program will also use a recursive algorithm to accomplish this.
String userWord = JOptionPane.showInputDialog(null, "Hello and welcome to the Word Pyramid program."
[Code] .....
So, if I input HORSE the output should be:
HORSE
ORS
R
How to read content of Word document ..?
View Replies View RelatedI 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 length 0
world
There are 0 words of length 1
how
There are 0 words of length 2
are
There are 3 words of length 3
you
There are 0 words of length 4