+ 1
please find error
public class Program { public static void main(String[] args) { int i; string str=new string("Hey its my first program on java and my second learning day...!!!!!"); for(i=0;i<length.str();i++) { System.out.println(str[i]); Thread.sleep(5); } } }
2 Antworten
+ 8
* string needs a capital S
* length.str() is reversed. It should be str.length()
* str[i] is not a valid syntax in java. (Because a string is not an array, and [] is only valid for arrays)
Use charAt() instead
Like:
str.charAt(i)
+ 1
import java.util.*;
import java.lang.*;
import java.io.*;
public class Program extends Thread
{
public static void main(String[] args)
{
int i;
String s1="Hey its my first program on java and my second learning day...!!!!!";
char[] str = s1.toCharArray();
int s = str.length;
for(i=0;i<s;i++)
{
System.out.println(str[i]);
}
}
}
this code is working by using str[i]