Click to See Complete Forum and Search --> : Please help on charAt


sweetflip4suh
03-03-2006, 08:30 PM
import java.util.Scanner;

public class Hello

{

public static void main ( String [] args)

{

int x, y, z, firstDigit;


String p;

Scanner scan = new Scanner ( System.in);
System.out.print ( " Please enter a number ");


p = scan.nextLine();

int length = p.length();


for ( int j = 0; j < length; j++)


System.out.print ( p.charAt(j) + "");
System.out.println ();
System.out.println (" now in reverse");

for ( int j = length - 1; j >=0 ; j --)



System.out.print ( (p.charAt(j) + 5) + " " );

}



}


//// i have problem on this line System.out.print ( (p.charAt(j) + 5) + " " );
it adds the number 5 to j output..........but only numbers shows...
and i try to use ( char( (p.charAt(j) + 5) + " " ); but i get error about .class

how do i turn it to letters and not numbers

im basically tryin to turn the letters to another letter...( shifting it)



}

srekcus
03-03-2006, 08:41 PM
Try this...

System.out.print((char)(p.charAt(j) + 5));

Your parentheses were kind of mixed up in your example.

System.out.print( char( (p.charAt(j) + 5) + " " );

sweetflip4suh
03-03-2006, 09:04 PM
thanks..!