Write A Program To Reverse Each Word In Line (sentence)

Jul 3, 2014

Write a program to reverse each word in line(sentence)?

View Replies


ADVERTISEMENT

How To Reverse Order Of Words In A Sentence

Nov 29, 2012

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

[code]....

View Replies View Related

Program To Count Character Word And Line From A File?

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

Deleting Word From Sentence

Feb 7, 2015

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....

View Replies View Related

Requiring User To Enter Word / Sentence To Encrypt Or Decipher

Apr 10, 2014

I've been given an assignment for my Programming Fundamentals class that requires the user to enter a word/sentence to encrypt or decipher, as well as requiring the user to enter a key in which to encrpyt/decrypt the input by.

So a = no shift, b = a shift by 1 and so on.

But I'm completely lost as to what to do, and after searching for Vigenere Cipher topics, they look completely different to mine and (hardly) include prompts?This is my code:

/**
* @(#)VigenereCipher.java
*/
import java.util.Scanner;
public class VigenereCipher
{
public VigenereCipher()

[code]....

View Replies View Related

Write Out Whole Sentence - Counting Characters

Sep 16, 2014

public class Setning

public static void main(String[] setning) {
skrivHeleSetningen(setning);
}
private static void skrivHeleSetningen(String[] setning) {
 
[Code] .....

What this do is:

First write out the whole sentence (WORKS)
Write out number of words (WORK)
Then I would like it to write out number of characters (DOESN'T WORK)

The arguments are given in "run configurations" using eclipse

View Replies View Related

Reverse Number - Get Input And Result In Same Line

Feb 11, 2015

I'm having trouble with a program, reversing numbers. I got the program itself to work! However, I am having an issue with the output.

import java.util.Scanner;
public class p1a {
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner input = new Scanner(System.in);
int n;
int reverse = 0;

[Code] .....

If I were to input, say 2341, I would get this: The reverse of 0 is 1432

The 0 should have been 2341, or whatever I input. What am I doing wrong?

I tried to move line 21 : (System.out.println("The reverse of " +n+ " is "+reverse);

Above the while loop, but instead get:

The reverse of 2341 is 0

How can I get my input and my result together in the same line?

View Replies View Related

Read Line From File And Save First String As Word And Remaining As Meaning

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

Output Contents Of Input File In Alphabetical Order One Word Per Line

Jun 22, 2014

I am having a lot of trouble with this lab. basically I have to make a text processor to read in code put it into a file and output the contents of the input file in alphabetical order one word per line. I have to reference the string varaibles input_filename and output_filename.

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;
import java.io.File;
public class TextProcessor {

[Code] ....

these are the guidelines to said lab:

1. In the main method define two Strings called input_filename and output_filename. I will be setting these Strings to my own file names for testing your code, so make sure you get these variable names correct, and that you use them properly in the following steps.
2. Read in the text contents of the file referenced by input_filename.
3. Split the contents of the input text into separate tokens, using whitespace as a delimiter.
4. Lower case the tokens.
5. OPTIONAL: remove punctuation
6. Alphabetize the tokens.
7. Using output_filename, write the alphabetized tokens to an output file, one token per line.
8. Be sure to close file streams - no resource leaks!
9. Use methods to separate functionality in your program where possible

View Replies View Related

Program To Convert All Vowels To Capital Letter In A Sentence?

Jul 3, 2014

i am new to programming skills it may be silly question for experience but for me it's new thing. actually i tried a lot but i am facing problem when i trying to take input through Scanner. if i will take input a sentence directly as a string it's working . but when i am trying with Scanner the first word is showing next are not showing

public class Demo2
{
public static void main(String[] args)
{
String s1="hi how are you";
s1=s1.replace('a', 'A');
s1 =s1.replace('e', 'E');
s1 =s1.replace('i', 'I');

[Code]...

this is working properly.

but when i trying with Scanner i am facing problem.

public class Demo2
{
public static void main(String[] args)
{
java.util.Scanner scn= new java.util.Scanner(System.in)
String s1=scn.next();
s1=s1.replace('a', 'A');

[Code]...

View Replies View Related

Make Program That Tells User To Type Sentence?

May 21, 2014

Ok, so I have to make a program that tells the user to type a sentence and at the end of the sentence a "." must be put to end the program. If a "." period is not entered, it must re-prompt the user to enter a period. On top of all this, the program has to count the number of letters in the sentence. I cant seem to get the while loop working and I cant find anywhere how to make a counter count the number of letters.

import java.io.*;
class Sentence
//The purpose of this program is to

[Code]....

View Replies View Related

Write A Method To Add Tag To Specific Word Regardless Of Case Or Punctuation

Mar 23, 2015

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) {

View Replies View Related

Telephone Number - Write To A File Every Possible Seven-letter Word Combination

Nov 23, 2014

I am having some trouble with this program. The assignment is to write a program, given a seven-digit phone number, uses a PrintStream object to write to a file every possible seven-letter word combination that corresponds to that number. I have to avoid using 0 or 1. Here is my code.

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Scanner;
public class TelephoneGenerator
{
String phoneNumber;
char numberLetters[][] = {

[Code] ....

I am getting an error dealing with the main class.

View Replies View Related

TxT File - Write In Next Line

Mar 5, 2014

i start work with TxT files. And i need know how to write text in the next line if file exist. My code just last text replace new.. Here code :

Main :
package YoYo;
import java.util.Scanner;
public class Main {
static String atsakymas;
static String FileName;
 
[code]....

View Replies View Related

Read / Write From Specific Line

Mar 17, 2014

I have a question for the read and write method in file.In my code for writing i m using PrintWriter and for reading Scanner.So i m saving data to file and when is need it i m reading from the file.but i also have to delete specific data from it.Is there a way to delete a specific line from the file?When i google my problem i found that is better to save your data to temporary file and then to the final.

View Replies View Related

Write Application That Display Numbers 1 To 4 On Same Line

Jul 22, 2007

I'm going to be taking an object oriented paradigm using java during intersession in a few months. I'm trying to brush up on it a bit. The problem is. Write an application that displays the numbers 1 to 4 on the same line, with each pair of adjacent numbers separated by one space. Write the program using the following techniques:Use one system.out.printLn statement.Use four system.out.print statement.Use one system.out.printf statement.

This is what i have so far .

Java Code: public class Display
{
public static void main(String [] args) {
System.out.print("1 ");
System.out.print("2 ");
System.out.print("3 ");
System.out.print("4 ");
System.out.println(" ");<----is that what that is supposed to look like, and where it goes?
System.out.printf(" %s %s %s %s ");????
}
} mh_sh_highlight_all('java');

i cant test this my console isn't working right, and i haven't finished my compiler install.

View Replies View Related

How To Write Import Statements And Use Its Class Components In One Line

Feb 5, 2015

I was wondering if I could write this code in one line.

import java.util.Scanner;
public class Test
{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
char ch = sc.next().charAt(0);
}
}

Can I combine "import java.util.Scanner","Scanner sc = new Scanner(System.in);" and "char ch = sc.next().charAt(0);" in one statement? The object created from the class Scanner may be anonymous but it doesn't concern me!

View Replies View Related

Order Of Numbers - Reverse Array Program

Apr 23, 2015

import java.util.Scanner;

public class ReverseOrder {
public static Scanner input = new Scanner(System.in);
public static void main(String[] args){
int[] numbers;
double[] reverse;

numbers = readArray();
reverse = reverseOrder(numbers);

[Code] ....

I have to write a program that takes an order of numbers and print the reverse order of those numbers.

the out put i receive is:

How many numbers do you want to enter?
4
Please enter 4 integers separated by a space:
1 2 3 4
Your numbers in reverse order are:[D@1f96302

View Replies View Related

Word Counter Program With A Constructor

Mar 4, 2014

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

[Code] .....

View Replies View Related

Creating Number To Word Program?

Apr 1, 2015

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?

View Replies View Related

How To Make Hangman Program Work For Phrases With More Than One Word

Apr 13, 2015

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;

[Code] ....

View Replies View Related

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;

[Code] ....

View Replies View Related

Program That Memorizes Elements Formed By A Word And A Number

May 24, 2014

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.

View Replies View Related

Multi-word Hangman Game - Spaces Not Displayed When Program Run

Apr 9, 2015

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;

[Code] ....

View Replies View Related

Command Line Program

Feb 8, 2014

I have a program that runs in the terminal (I use Ubuntu). It asks the user for a String, does something with it, and terminates.It works in the NetBeans terminal, but not outside of it. Specifically, regardless of what I input, it doesn't continue with the program. I enter something, press enter and it just goes to the next line in the terminal.

Java Code:

Scanner scan=new Scanner(System.in);
System.out.println("Enter the music directory:");
String path=scan.nextLine(); mh_sh_highlight_all('java');

how do I pass in arguments when I run the program (still in Linux)? Is there a way to check if the program was launched from the terminal or not?

View Replies View Related

Java Program To Translate English Into Pirate - Word Pair Class

Apr 5, 2015

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)
 
[Code] .....

View Replies View Related







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