View Single Post
  #2 (permalink)  
Old 02-01-2008, 01:53 PM
jelly's Avatar
jelly jelly is offline
Member
 
Join Date: Jan 2008
Location: Somerset, UK
Posts: 46
jelly is on a distinguished road
this should help you to get going

Code:
String digits; Scanner scan = new Scanner (System.in); System.out.print ("Please enter a five digit number: "); digits = scan.nextLine(); String n1 = digits.substring(0,1) ; String n2 = digits.substring(1,2) ; System.out.println (n1+ "\t" + n2+ "\t" );
the parameters for substring can be confusing at first. The first parameter is the index of the string that you want to start from, the second parameter is the end index and the string will be substringed up to the endindex -1, or another way of looking at it. The first parameter is the index of the string that you want to start from, and the second parameter - the first parameter gives the length of the substring
__________________
-- Hope that helps
Reply With Quote