KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > java > lang > StringIndexOutOfBoundsException

java.lang
Class StringIndexOutOfBoundsException

java.lang.Object
  extended by java.lang.Throwable
      extended by java.lang.Exception
          extended by java.lang.RuntimeException
              extended by java.lang.IndexOutOfBoundsException
                  extended by java.lang.StringIndexOutOfBoundsException
All Implemented Interfaces:
Serializable
See Also:
Top Examples, Source Code, String.charAt(int)

public StringIndexOutOfBoundsException()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1390]_
By Dr { dot } Mails { at } Gmail { dot } com on 2005/04/13 16:46:41  Rate
exception: java.lang.StringIndexOutOfBoundsException: -1

public StringIndexOutOfBoundsException(int index)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1891]replacing rhe character
By nani4u { dot } koti { at } gmail { dot } com on 2007/06/14 23:26:49  Rate
import java.io.*; 
 class N1 
  { public static void main ( String args [  ]  )  
  {  
         DataInputStream dis=new DataInputStream ( System.in ) ; 
         System.out.println ( "enter the string:" ) ; 
     String s1=dis.readLine (  ) ; 
     System.out.println ( "Enter The Char u want to Repalce.. :" ) ; 
         String c1=dis.readLine (  ) ; 
     System.out.println ( " with...... :" ) ; 
         String c2=dis.readLine (  ) ; 
 //StringBuffer s=new StringBuffer ( "hello" ) ; 
 //StringBuffer s1=new StringBuffer ( "l" ) ; 
 //StringBuffer s2=new StringBuffer ( "" ) ; 
 int n=s1.length (  ) ; 
 for ( int i=0;i < n;i++ )  
  {  
 if ( s1.charAt ( i ) ==c1.charAt ( 0 )  )  {  
 s1.setCharAt ( i,'x' ) ; 
  }  }  
 System.out.println ( s1 ) ; }  } 


public StringIndexOutOfBoundsException(String s)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[660]StringIndexOutOfBoundsException
By angelo_e_fleming { at } yahoo { dot } com on 2004/02/11 21:29:35  Rate
Error #: 2301 : internal compiler error: java.lang.StringIndexOutOfBoundsException: String index out of range: -2 
  
  
 import java.io.*; 
 import javax.swing.*; 
  
  
 public class Realtor 
  {  
  
  
 public static void main ( String [  ]  args )  
  {  
  
  
         String owner; 
         String priceString; 
         String outPutStr; 
         double price; 
         final double RATE = 0.06; 
         final double COMMISSION = 0.015; 
  
  
         //Program information 
         System.out.println ( "\nThis program calculates the cost to sell a home\n" 
                 + "and the commission paid to an individiual sales agent.\n\n" 
                 + "The user is asked for the last name of the seller and the " 
                 + "sales price\n\n" ) ; 
  
  
  
         //gets the owner's name from the user 
         owner = JOptionPane.showInputDialog ( "Please enter owners last name: " ) ; 
  
  
  
         //gets the price value from the user 
         priceString = JOptionPane.showInputDialog ( "Please enter the sales price" 
                                                   + " of the home" ) ; 
  
  
         //passes the priceString value to price 
         price = Double.parseDouble ( priceString ) ; 
  
  
         //Calculations 
         //Have to be in String form for out box 
         outPutStr = "\n\nThe " + owner + "\'s home sold for " 
                 + price + "\nThe cost to sell the home was " +  ( RATE * price )  
                 + "\nThe selling or listing agent earned " 
                 +  ( COMMISSION * price ) ; 
         JOptionPane.showMessageDialog ( null, outPutStr, "Realtor", + 
                                      JOptionPane.INFORMATION_MESSAGE ) ; 
  
  
  System.exit ( 0 ) ; 
   }  
  } 

Popular Tags