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

"==" is the operator, not "= ="

and, of course, if the if statement fails, the else will be out of place.
So there will be no output as there is a syntax error right??
Similar Questions
    1. answers icon 4 answers
  1. class professor {};class teacher : public virtual professor {}; class researcher : public virtual professor {}; class
    1. answers icon 1 answer
  2. The code below shows some of the text for a class called City.Now write a complete public constructor with two formal
    1. answers icon 1 answer
  3. Here is the source code for the Kitty class:public class Kitty { String name; int age; public Kitty(){ } public void
    1. answers icon 2 answers
more similar questions