Java programming 1

Java programming 1

View Answers

December 2, 2008 at 12:34 AM

Hi friend,

Code to solve the problem :


class InsertWord
{
public static String insertWord(String sentence, String word, int position)
{
String sentenceAr[] = sentence.split(" ");
String strAr[] = new String[sentenceAr.length+1];
String stringResult=" ";
if(position==0)
{
System.out.println("position : " + position);
strAr[0] = word;
stringResult +=" "+strAr[0];
for(int i=1;i<strAr.length;i++)
{
strAr[i] =sentenceAr[i-1];
stringResult +=" "+ strAr[i] + " ";
}
}
else if(position!=0)
{

for(int i=0;i<position;i++)
{
strAr[i] =sentenceAr[i];
stringResult +=" "+ strAr[i];
}
strAr[position] =word;
stringResult +=" "+ strAr[position];
for(int i=position+1;i<strAr.length;i++)
{
strAr[i] =sentenceAr[i-1];
stringResult +=" "+ strAr[i];
}
}


return stringResult;

}
public static void main(String[] args)
{
String sentence ="Hello World";
String word ="Roseindia";
int position = -1;
String sentenceAr[] = sentence.split(" ");
if(!(position>sentenceAr.length || position<0))
System.out.println(insertWord(sentence, word, position));
else
System.out.println(sentence);
}
}

For more information on Java visit to :

http://www.roseindia.net/java/

Thanks









Related Tutorials/Questions & Answers:
Java programming 1 - Java Beginners
Java programming 1  Thx sir for reply me ^^ err how bout if using scanner class or further method to solve that code? instead of using array?  ...://www.roseindia.net/java/java-tips/examples-introductory/console/console-input
Java programming 1 - Java Beginners
Java programming 1  thx sir for reply me..but sir can u pls simplify... programming ...n i jus learn until simple method not further method yet..haha   Hi friend, 1. Ask the user for their height. Convert it to a double
Advertisements
Java programming 1 - Java Beginners
Java programming 1  Hi sir, i facing problem in this program. This program requires passing arrays as parameters and returning arrays from methods.../java/example/java/swing/ Thanks
Java programming 1 - Java Beginners
Java programming 1  write one program, which consists of a main...? There are nine words in total Java has a standard to index elements starting... be at position 1, etc ?A sentence is constructed with a series of words? Index 0 1 2 3 4
Java programming 1 - Java Beginners
Java programming 1  write one program, which consists of a main...? There are nine words in total Java has a standard to index elements starting... be at position 1, etc ?A sentence is constructed with a series of words? Index 0
Java programming 1 - Java Beginners
Java programming 1  hi there, Sir! Can u help me check where my program gone wrong? here are my coding =D, hope to get reply from u guys soon... = JOptionPane.showInputDialog(null,"Enter mark 1", "Homework 8",JOptionPane.QUESTION_MESSAGE
Java Programming
Java Programming  Hi, What is Java Programming? How I can learn Java Programming in one month? Thanks
java code7 of 1
java code7 of 1  Develop the program calculateHeight, which computes the height that a rocket reaches in a given amount of time. If the rocket accelerates at a constant rate g, it reaches a speed of g Ã?· t in t time units
java code 8 of 1
java code 8 of 1  Develop a program that computes the distance a boat travels across a river, given the width of the river, the boat's speed perpendicular to the river, and the river's speed. Speed is distance/time
java code 1 of 2
java code 1 of 2  Create a washing machine class with methods as switchOn, acceptClothes, acceptDetergent, switchOff. acceptClothes accepts the noofClothes as argument & returns the noofClothes   Hi Friend, Visit
task 1 - Java Beginners
task 1  Please write a Java client that send a small letters string to a Java server which convert it to uppercase letters and send it back to the client. Please submit both the client and server programs  Hi Friend
java program 1
java program 1  (4) WAP to take input of a String and check wheather it is valid number or not? Sample Output1: Enter a String : 10 10 is a number Sample Output2: Enter a String : 10b1 10b1 is not a number (5) WAP to take
java code 1 of 2
java code 1 of 2  Create a washing machine class with methods as switchOn, acceptClothes, acceptDetergent, switchOff. acceptClothes accepts the noofClothes as argument & returns the noofClothes   Hi Friend, Try
problem 1 - Java Beginners
problem 1   Hi, please help me!!!! How can i code in java using Two-dimensional Arrays? This question is related to the one i posted before. this is my input data file: 88 90 94 102 111 122 134 75 77 80 86 94 103 113 80
function 1 - Java Beginners
function 1  WAP to calculate the value of x,where x=tan(A)+tan(B)/1+tan(A)*tab(B)  Give more details like how to calculate and what is tan(A) and tan(B),etc
que 1 - Java Beginners
que 1  WAP to enter a sentence & count the no. of times a particular word occurs in it.Display the frequency of the searched word. eg- input:the quick brown fox jumps over the lazy dog. word to be searched:the output
array 1 - Java Beginners
array 1  WAP to input values in 2 arrays and merge them to array M.  Hi Friend, Try the following code: import java.util.*; class MergeArray{ public static int[] merge(int [] ... arr) { int arrSize = 0
java programming
java programming   Companies and people often buy and sell stocks... in question Implement the program described above using the Java programming language... programming method you want to accomplish this task. Both your stack and queue
java programming
java programming   Companies and people often buy and sell stocks... in question Implement the program described above using the Java programming language... programming method you want to accomplish this task. Both your stack and queue
programming - Java Beginners
programming for java beginners  How to start programming for java beginners
programming - Java Beginners
Start programming in Java  Programming in Java - Can any one please suggest how to start programming in Java
Java Programming
Java Programming  Write a Java program that prompt user to input a number of students in a class. Then, prompt user to input the studentÃ?¢ââ??‰â??¢s programming mark. Determine how many student get A+ and A for their grade
java programming
java programming  Write a Java program that prompt user to input a number of students in a class. Then, prompt user to input the studentâ??s programming mark. Determine how many student get A+ and A for their grade and how many
java programming
java programming  Write a complete Java Program that correctly does the following: prints out first 1000 numbers (not including 1000... Number 1 - Odd Number - 2 Even . . . Number 999 - Odd
Java programming
Java programming  What is the Role of OOP in java
Java programming
Java programming  What is the Role of OOP in java
java programming
java programming  Hi, now am analysing one project from that project... = jslNClusters.getValue(); //3; int Rows = jtblCluster.getRowCount() - 1; int...++) { Datasets[r] =Float.valueOf(jtblOriginal.getValueAt(r, 1).toString
java programming
java programming  A computer is used to count the votes.... Suppose this value is N â?? candidates will then be numbered 1 to N. Each elector in turn has ONE chance to choose his candidate from 1 to N
java programming
java programming  how to write a coding for simple login form in netbeans
java programming
java programming  what is taxonomy tree why we use that concept in java   hierarchical taxonomy is a tree structure of classifications for a given set of objects
Java Programming
Java Programming  Using Java Frame form, help me develop a GPA calculating device, able to show Grade and points together, and using MySQL database
Java Programming
Java Programming  Using Java Frame form, help me develop a GPA calculating device, able to show Grade and points together, and using MySQL database
JAVA PROGRAMMING
JAVA PROGRAMMING  Write an OVERLOADED FUNCTION in java that swaps(interchanges) 2 user given numbers.(one integer and one float value) and displays the result after swapping. Invoke the function in a class
java programming
java programming  how to count the no. of constants in a user given string?? plzz help
java programming
java programming  Hi friends, if i create one project what are the step i can make...... i need step by step procedure
java programming
java programming  WAP to calculate the sum of: x + x(square)/2 + x(cube)/3 +.......... x(to the power n)/n
java programming
java programming  supose i have a text field in java (like in gmail home page u have username field ) so i want to fill that field automatically by taking record from the database so is there any mechanism in java to handle
java programming
java programming  Hi, do u have any idea about these lines? Hashtable<Integer,JLabel> labels = new Hashtable<Integer,JLabel>(); labels = new Hashtable<Integer,JLabel>
java programming
java programming  Hi friends i need simple login form coding using two labels,two textfields and two buttons in netbeans without using database connection. . if you know that logic please tell
java programming
java programming  Hi friend if you have any idea about this statement please tel me... String qry1="select * from custentry1 where custid='"+custno
java programming
java programming  Hi friends, i need a simple login form source code. in that program i have two labels,two text fields and two buttons namely ok and cancel buttons. how to write for that one using netbeans without database
java Programming
java Programming  Based on the following algorithm, write a Java Program Start defining the MyClass class. Declare the class?s myField data field. Initialize the data field. Start defining the SetField() method. Set
Java Programming
Java Programming  Assume that bank maintains two kinds of accounts...://www.roseindia.net/tutorial/java/core/bankAccountApplication.html   thnk...://www.roseindia.net/answers/viewqa/Java-Beginners/27008-q-in-java.html
java programming
java programming  How can be uesd in graphiclly view for user inter (x,y) cordinate and show the output shart point to end point. java code,,????   import org.jfree.chart.*; import org.jfree.chart.plot.PlotOrientation
java programming
java programming  How can be uesd in graphiclly view for user inter (x,y) cordinate and show the output shart point to end point. java code,,????   import org.jfree.chart.*; import org.jfree.chart.plot.PlotOrientation
java programming
java programming  How can be uesd in graphiclly view for user inter (x,y) cordinate and show the output shart point to end point. java code,,????   import org.jfree.chart.*; import org.jfree.chart.plot.PlotOrientation
Java programming
Java programming  Hello! Is anybody able to do this task: I need to find the percentage of words distribution between parts of speech. I have to mark nouns, verbs, adjectives and perpositions like that: to the end of noun
java programming
java programming  abstract class demo { void play() { System.out.println("hello"); } void play2() { System.out.println("hi there"); } } class abs extends demo { public static
Java Programming
Java Programming  A developer wants you to develop a simple take away restaurant order service. The system reads from a file containing information about the restaurants (such as the name, place and menu). The system then allows
JAVA PROGRAMMING
JAVA PROGRAMMING  WAP to generate the following Series * * * * * * * * * * * * * * *   class Pyramid{ public static void main(String[] args

Ads