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?
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
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.