what is wrong in this code
Code java:
import java.util.*;
public class charPerLine {
public static void main(String[] args)throws StringIndexOutOfBoundsException {
Scanner sc=new Scanner(System.in);
System.out.print("Type any name:");
String s=sc.next();
int j= s.length();
for(int i=0;i<=j;i++){
char ch=s.charAt(i);
System.out.println(ch);
}
}
}
Re: what is wrong in this code
For future reference, please flank your code with the [highlight=java][/highlight] tags. I've edited your post for you.
Quote:
what is wrong in this code
You need to tell us...does it compile? Are there exception? Does it behave? What exactly is the problem and/or question?
Re: what is wrong in this code
I think it should be going from 0 to less than j. Not less than or equal to j.
Code java:
import java.util.*;
public class charPerLine {
public static void main(String[] args)throws StringIndexOutOfBoundsException {
Scanner sc=new Scanner(System.in);
System.out.print("Type any name:");
String s=sc.next();
int j= s.length();
for(int i=0;i<j;i++){
char ch=s.charAt(i);
System.out.println(ch);
}
}
}