Ashley P.

asked • 11/10/19

Java String class

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?

1 Expert Answer

By:

Patrick B. answered • 11/11/19

Math and computer tutor/teacher

Ashley P.

Thank you very much for the explanation!
Report

11/17/19

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.