Asked by Arya

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?

Answers

Answered by oobleck
"==" is the operator, not "= ="

and, of course, if the if statement fails, the else will be out of place.
Answered by Aryaa
So there will be no output as there is a syntax error right??

Related Questions