So we are given to write the exact output of the following code:
class stri123{
public static void main(String[] args) {
String name = "University Grants Commission";
boolean sword = true;
for(int i = 0; i < name.length(); i++){
if(sword)
System.out.println(name.charAt(i) );
if(name.charAt(i) = = '')
sword = true;
else
sword = false;
}
}
}
I coded this on NetBeans and found it is showing errors at the following lines(** represent error-indicating lines);
if(name.charAt(i) = = '') **
sword = true;
else **
sword = false;
What could possibly be the reasons for these errors and what is the exact output of the above code?
2 answers
and, of course, if the if statement fails, the else will be out of place.