Link to home
Start Free TrialLog in
Avatar of gudii9
gudii9Flag for United States of America

asked on

difference of code nested for

package com.bharaththippireddy.trainings.jaxrs;

public class NestedFor2 {

	public static void main(String[] args) {
		for (int i = 1; i <= 3; i++) {
			for (int j = 1; j <= 2; j++) {
			System.out.print("six");
			}
			}
			

}
}

Open in new window


what is difference between above and below program


package com.bharaththippireddy.trainings.jaxrs;

public class NestedFor2 {

	public static void main(String[] args) {
		for (int i = 1; i <= 3; i++) {
			for (int j = 1; j <= 2; j++) {
			System.out.println("six");
			}
			}
			

}
}

Open in new window


both cases i am getting same output as
six
six
six
six
six
six


when i run inside main class
package com.bharaththippireddy.trainings.jaxrs;

public class NestedFor2 {

      public static void main(String[] args) {
            for (int i = 1; i <= 3; i++) {
                  for (int j = 1; j <= 2; j++) {
                  System.out.print("six");
                  }
                  }
                  

}
}

please advise
ASKER CERTIFIED SOLUTION
Avatar of dpearson
dpearson

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gudii9

ASKER

yes

sixsixsixsixsixsix


public class NestedFor2 {

      public static void main(String[] args) {
            for (int i = 1; i <= 3; i++) {
                  for (int j = 1; j <= 2; j++) {
                  System.out.print("six");
                  }
                  }
                  

}
}