Home Answers Viewqa Java-Beginners Java programming 1

 
 


Kaito
Java programming 1
1 Answer(s)      4 years and 6 months ago
Posted in : Java Beginners

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 Pages:
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
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 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: Chapter 1
Chapter 1 Overview: The Mental Landscape WHEN YOU BEGIN a journey... is and how one is created. Since you will be writing programs in the Java programming language, you'll want to know something about that language
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: Chapter 1 Quiz
Quiz Questions For Chapter 1 THIS PAGE CONTAINS A SAMPLE quiz on material from Chapter 1 of this on-line Java textbook. You should be able... is a subroutine? Question 7: Java is an object-oriented programming language. What
Java Programming: Chapter 1 Quiz Answers
Sample Quiz Answers For Chapter 1 THIS PAGE CONTAINS SAMPLE ANSWERS to the Quiz on Chapter 1 of this on-line Java textbook. Note... 1: One of the components of a computer is its CPU. What is a CPU and what
Programming
Programming  how to save output of java file in .txt format?  ...; bracket to direct the output to a text file. Here is the example: C:>java...; public class Redirecting extends Thread { private int count = 1; private int
Logging Tutorial - Part 1
Logging Tutorial - Part 1 2000-12-14 The Java Specialists' Newsletter [Issue 003] - Logging part 1 Author: Dr. Heinz M. Kabutz If you are reading... to the third "The Java(tm) Specialists' Newsletter", a low-volume newsletter
Chapter 1. EJB Overview
the Write Once, Run Anywhere™ philosophy of the Java programming...  Chapter 1. EJB OverviewPrev Part I. Exam Objectives Next    Chapter 1. EJB
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
Programming: Initials 1
Java: Programming: Initials 1 Name ________________________________________ Write a program that asks for names and displays the initials. Ask the user for their first name. Save it in a string variable. Ask the user for their last
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
How to Create Multiplication Table from 1 to 10?
to 10 using in Java programming language. I had read an articles last month where...How to Create Multiplication Table from 1 to 10?  Hi, I want... table 1 to 10. Please suggest online example related to creating multiplication
Java Programming: Solution to Programming Exercise
Solution for Programming Exercise 9.3 THIS PAGE DISCUSSES ONE POSSIBLE SOLUTION to the following exercise from this on-line Java textbook... 100 I 1 L 50 When letters are strung together
Java Programming: Solution to Programming Exercise
Solution for Programming Exercise 9.4 THIS PAGE DISCUSSES ONE POSSIBLE SOLUTION to the following exercise from this on-line Java textbook.... For example, if Expr represents the expression 3*x+1, then func.value(5) is 3*5
java programming - Java Beginners
Java programming - reverse string in java  Hi all, I am looking for a Reverse string example in Java.  class reverse { public static void main(String[] args) { String str = "Java Program"; String reversestr
Java Programming: Solution to Programming Exercise
is not 1, that is, that either die1 is not 1 or die2 is not 1. In java code... Solution for Programming Exercise 3.1 THIS PAGE DISCUSSES ONE POSSIBLE SOLUTION to the following exercise from this on-line Java textbook
programming
Java Constructor programming for single and double constructor  write a program which have no argument constructor ,single parameter constructor constructor,double parameter constor,and the now when we create a object
Java Programming: Solution to Programming Exercise
Solution for Programming Exercise 3.2 THIS PAGE DISCUSSES ONE POSSIBLE SOLUTION to the following exercise from this on-line Java textbook. Exercise 3.2: Which integer between 1 and 10000 has the largest number
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 Programming: Solution to Programming Exercise
Solution for Programming Exercise 4.3 THIS PAGE DISCUSSES ONE POSSIBLE SOLUTION to the following exercise from this on-line Java textbook... 3.1. The main difference is that instead of rolling until both dice come up 1
Java Programming: Solution to Programming Exercise
Solution for Programming Exercise 2.2 THIS PAGE DISCUSSES ONE POSSIBLE SOLUTION to the following exercise from this on-line Java textbook... simulate rolling one die by choosing one of the integers 1, 2, 3, 4, 5, or 6
Java Programming: Solution to Programming Exercise
Solution for Programming Exercise 6.4 THIS PAGE DISCUSSES ONE POSSIBLE SOLUTION to the following exercise from this on-line Java textbook... the programming into a drawing surface class named Board. Besides this nested class
Java Programming: Solution to Programming Exercise
Solution for Programming Exercise 9.2 THIS PAGE DISCUSSES ONE POSSIBLE SOLUTION to the following exercise from this on-line Java textbook. Exercise 9.2: As discussed in Section 1, values of type int are limited to 32
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
Java Programming: Solution to Programming Exercise
Solution for Programming Exercise 4.2 THIS PAGE DISCUSSES ONE POSSIBLE SOLUTION to the following exercise from this on-line Java textbook... letters. If the parameter is not one of the legal hexadecimal digits, return -1
Java Programming, Solution to Programming Exercise
. Some languages use predicates in generic programming. Java doesn't... Solution for Programming Exercise 12.4 THIS PAGE DISCUSSES ONE POSSIBLE SOLUTION to the following exercise from this on-line Java textbook
Java Programming, Solution to Programming Exercise
Solution for Programming Exercise 12.1 THIS PAGE DISCUSSES ONE POSSIBLE SOLUTION to the following exercise from this on-line Java textbook...: return stack.remove(stack.size()-1); If the ArrayList
Java Programming: Solution to Programming Exercise
Solution for Programming Exercise 10.5 THIS PAGE DISCUSSES ONE POSSIBLE SOLUTION to the following exercise from this on-line Java textbook... command lines can be used to run the client: java FileClient 172.0.0.1
Java Programming: Solution to Programming Exercise
Solution for Programming Exercise 3.5 THIS PAGE DISCUSSES ONE POSSIBLE SOLUTION to the following exercise from this on-line Java textbook..., then 60, 80, 100, 120, and 140. If we assume that the rows are numbered 0, 1, 2
Java Programming: Solution to Programming Exercise
Solution for Programming Exercise 6.1 THIS PAGE DISCUSSES ONE POSSIBLE SOLUTION to the following exercise from this on-line Java textbook... from 1 to 6 dots. Since you have to draw two dice, its a good idea to write
Java Programming: Solution to Programming Exercise
Solution for Programming Exercise 4.1 THIS PAGE DISCUSSES ONE POSSIBLE SOLUTION to the following exercise from this on-line Java textbook...), but str.charAt(i-1) doesn't exist if i is 0. Let's look at Java code
Java Programming: Solution to Programming Exercise
Solution for Programming Exercise 6.3 THIS PAGE DISCUSSES ONE POSSIBLE SOLUTION to the following exercise from this on-line Java textbook... Java. (Note: Since there was only one button in this applet, I added
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
Java Programming: Solution to Programming Exercise
Solution for Programming Exercise 4.5 THIS PAGE DISCUSSES ONE POSSIBLE SOLUTION to the following exercise from this on-line Java textbook..., they must be specified in the Mosaic.setColor() routine. Written in Java, the body
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
Java Programming: Solution to Programming Exercise
Solution for Programming Exercise 4.6 THIS PAGE DISCUSSES ONE POSSIBLE SOLUTION to the following exercise from this on-line Java textbook... doesn't look too good in many versions of Java.) The applet
java programming - Java Beginners
java programming  asking for java code .. counting for how many times... is best output: a -- 1 b -- 1 e -- 2 i -- 2 n -- 2 l -- 1 s -- 1 t -- 1 help me plz... thank u ahead   Hi Friend, Try the following
Java Programming, Solution to Programming Exercise
Solution for Programming Exercise 12.5 THIS PAGE DISCUSSES ONE POSSIBLE SOLUTION to the following exercise from this on-line Java textbook... and output files. Let lineNum = 1. Repeat
Java Programming: Solution to Programming Exercise
Solution for Programming Exercise 8.2 THIS PAGE DISCUSSES ONE POSSIBLE SOLUTION to the following exercise from this on-line Java textbook...(double[] A, int count) { // Sort the numbers in A[0], A[1
Java Programming: Solution to Programming Exercise
Solution for Programming Exercise 4.4 THIS PAGE DISCUSSES ONE POSSIBLE SOLUTION to the following exercise from this on-line Java textbook...; // Numbers between 1 and 6 representing the dice. int roll
Java Programming: Solution to Programming Exercise
Solution for Programming Exercise 8.3 THIS PAGE DISCUSSES ONE POSSIBLE SOLUTION to the following exercise from this on-line Java textbook... with vertices at (xCoords[0],yCoords[0]), (xCoords[1],yCoords[1]), ..., (xCoords
Java Programming: Solution to Programming Exercise
Solution for Programming Exercise 5.1 THIS PAGE DISCUSSES ONE POSSIBLE SOLUTION to the following exercise from this on-line Java textbook... between 1 and 6. die1 = (int)(Math.random()*6) + 1
java programming - Java Beginners
java programming  Hi Buddies, i want java Array ,looping... is write a program in java to print * * * * * * * * * * the o/p...[] args) { for(int i=1;i<=4;i++) { for(int j=1;j<=i;j