Results 1 to 2 of 2
- 10-30-2011, 12:25 AM #1
Member
- Join Date
- Oct 2011
- Posts
- 19
- Rep Power
- 0
How Can i already be stuck? String play java
public class test
{public static void main (String[] args)
{
String word = "rotatemeplease";
String LastFour = "";
LastFour =word.substring(9, 4);
System.out.println(LastFour);
}
}
I should be able to get the last 4 letters into LastFour. Help. out of range error
-
Re: How Can i already be stuck? String play java
@tripline: Look at the String api to see how to use substring with two parameters correctly. The second parameter is not the length of the substring but the second index.
Also, you'll want to use code tags when posting code to this forum so your code will look like this:
Not like this:Java Code:public class Test { public static void main(String[] args) { String word = "rotatemeplease"; String LastFour = word.substring(word.length() - 4, word.length()); System.out.println(LastFour); } }
public class Test {
public static void main(String[] args) {
String word = "rotatemeplease";
String LastFour = word.substring(word.length() - 4, word.length());
System.out.println(LastFour);
}
}
@skaterboy: Please look at the API too so you will now know how to use substring with two parameters correctly and can give good advice for a similar question. Also please don't encourage the use of "magic" numbers.
Similar Threads
-
How to play movie using java
By sithara in forum New To JavaReplies: 3Last Post: 02-20-2013, 12:29 PM -
how to play a video from a file using jmf in a java
By 200808147 in forum New To JavaReplies: 0Last Post: 07-10-2011, 12:20 PM -
help to play file.wav in java
By jperson in forum New To JavaReplies: 2Last Post: 03-26-2010, 03:10 AM -
I want play chess in Java
By ganzorig in forum Advanced JavaReplies: 6Last Post: 11-15-2009, 04:53 AM -
how can I play an mp3 file in java?
By iliana in forum NetworkingReplies: 1Last Post: 05-30-2008, 07:32 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks