Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Thayanithy
Joption pane
1 Answer(s)      6 years ago
Posted in : Java Beginners



Advertisement
View Answers

December 3, 2008 at 5:12 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);
}
}

Thanks


Related Tutorials/Questions & Answers:
Joption pane - Java Beginners
Joption pane  The problem A sentence can be thought of as one or more words which are delimited by spaces. For example: ?A sentence is constructed with a series of words? The first word is ?A? The second word is ?sentence
accordion pane - Ajax
accordion pane  Is it possible to change the content of an accordion pane promgramatically? I wrote : function modif_pane1(){ dijit.layout.byId("pane1").content="string"; } but that's don't work
Advertisements
how to send joption panel dialog from server to multipleclients using sockets?
how to send joption panel dialog from server to multipleclients using sockets?  how to send joption panel dialog from server to multipleclients using sockets?like we get a first message with 2 buttonsand on clicking one button we
how to send joption panel dialog from server to multipleclients using sockets?
how to send joption panel dialog from server to multipleclients using sockets?  how to send joption panel dialog from server to multipleclients using sockets?like we get a first message with 2 buttonsand on clicking one button we
how to send joption panel dialog from server to multipleclients using sockets?
how to send joption panel dialog from server to multipleclients using sockets?  how to send joption panel dialog from server to multipleclients using sockets?like we get a first message with 2 buttonsand on clicking one button we
Java scroll pane-java GUI
Java scroll pane-java GUI  Dear friends.. Very Good morning. I have a doubt in my gui application. Take ex:- My gui application has 1 Jscrollpane of height 600 and width 400. normally it is showing 200 height and 400 width
how add tabs at the left side of a pane
how add tabs at the left side of a pane  sir i have added the tabs at the top left corner of the pane, but i am unable to add it at the left side of the pane, so please help me
Create a Desktop Pane Container in Java
Create a Desktop Pane Container in Java   ... pane container in Java. The desktop pane container is a container, which has.... The desktop pane is like a MDI (Multiple Document Interface) frame and all internal
Create a Scroll Pane Container in Java
Create a Scroll Pane Container in Java   ... to create a scroll pane container in Java Swing. When you simply create a Text Area... for the result of the given program: This program shows a scroll pane
problem in adding a fullscreen frame nd adding a glass pane to it
problem in adding a fullscreen frame nd adding a glass pane to it  hi , here is my code import java.awt.*; import javax.swing.*; import...(){ setTitle("glass pane"); Dimension d=ToolKit.getDefaultToolKit().getScreenSize
Set the Color of a Tab in a Tabbed Pane Container in Java
Set the Color of a Tab in a Tabbed Pane Container in Java... will learn how to set colors for a tab in a tabbed pane container in Java Swing... shows you how to set the color for each tab in the tabbed pane container
Freeze And Split Pane
freeze and split pane     ... sheets, we use  freeze the pane in different ways and in last one we split...; for the top row visible in bottom pane and leftmostColumn  for the left column
Excel Splits Pane Feature
Excel Splits Pane Feature In this section, you will learn how to split... of the sheet. This can be done using Excel Splits Pane Feature. Using... of the split. The last parameter indicates which pane currently has the focus
Excel Freeze Pane Feature
Excel Freeze Pane Feature In this section, you will learn about freezing row of excel document using Apache POI library. Sometimes when you scroll down too... which cell belongs to which heading. The solution of this problem is Freeze Pane
Java JTabbedPane Example
Java JTabbedPane Example In this section we will discuss about how to add the Tab pane in JFrame. javax.swing.JTabbedPane provides the feature to add tabs...(lab8); tp=new JTabbedPane(); Container pane
SplitPane in Java Swing
Learn SplitPane in Java Swing In this section, you will learn how to create split pane using java swing. For this, we have used JSplitPane class. Basically this class is used to divide two components. Here splitpane
Simple input application in Echo3
a text and this value would be shown into the content pane when user will click
Tomahawk pannelTabbedPane tag
to create a tabbed pane. Its has the capability of switching the tabs at client... input, #_idJsp0 .myFaces_panelTabbedPane_pane, #_idJsp0 .myFaces
Java prog - Java Beginners
Java prog  Write a program on Java that ask the user to input: Cost of Machine, Life of Machine, Cost of capital in Percentage, in an JOption pane... as ur requirement. import javax.swing.JOptionPane; public class JOption
java programming - Java Beginners
java programming  I need a java program that will add,edit,delete,view,save and print any information..it could be a JOption application..tnx  Hi Friend, Do you want to use database?Please clarify this. Thanks
jtabbedpane
jtabbedpane  how to add a close button in jtabbed pane using java swing
jsplitpane - Java Beginners
jsplitpane  Hi, I need the example code for jsplitpane. I have divided into two splitpanes,while i am click the left side pane text or button... side pane "using JPanel". Please send the code as soon as possible. Thanks
jsplitpane - Java Beginners
jsplitpane  Hi, I need the example code for jsplitpane. I have divided into two splitpanes,while i am click the left side pane text or button... side pane using "JPanel". Please send the code as soon as possible. Thanks
color changing - Java Beginners
){ JFrame frame = new JFrame("Tabbed Pane Frame..., BorderLayout.CENTER); tab.add("Tab 1", new JLabel("This is Tabbed Pane 1")); tab.add("Tab 2", new JLabel("This is Tabbed Pane 2")); tab.add("Tab 3", new JLabel
Change the color of the selected tab
created a tabbed pane and add four tabs to it. The UIManager.put("... void main(String[] args) { JFrame frame = new JFrame("Tabbed Pane Frame...(tab, BorderLayout.CENTER); tab.add("Tab 1", new JLabel("This is Tabbed Pane 1
JSP - Java Beginners
class TableApplet extends Applet{ JTable table; JScrollPane pane; public void..."} }, new String[] {"Name", "Address"}); pane=new JScrollPane(table); add(pane); setSize(300,100); } } 2)jtable.jsp
XML and swings - Java Beginners
XML and swings  I have an xml file where all the contents that should be present in the tabbed pane are there. i would like to know how to parse the xml such that, whenever it reads the component type as label, it should create
Advertisements
 

 

 

DMCA.com