Skip to main content
added 10 characters in body
Source Link
Marko Topolnik
  • 200.9k
  • 31
  • 336
  • 455

Your program is entirely correct; all you need to change is the location of the print statement:

public static void main(String[] args) {
  int f = 0;
  int g = 1;

  for(int i = 1; i <= 10; i++)
  {
    System.out.print(f + " ");
    f = f + g;
    g = f - g;
  } 

  System.out.println();
}

//... or Alternatively, print gg instead of ff.

Your program is entirely correct; all you need to change is the location of the print statement:

public static void main(String[] args) {
  int f = 0;
  int g = 1;

  for(int i = 1; i <= 10; i++)
  {
    System.out.print(f + " ");
    f = f + g;
    g = f - g;
  } 

  System.out.println();
}

//... or print g instead of f.

Your program is entirely correct; all you need to change is the location of the print statement:

public static void main(String[] args) {
  int f = 0;
  int g = 1;

  for(int i = 1; i <= 10; i++)
  {
    System.out.print(f + " ");
    f = f + g;
    g = f - g;
  } 

  System.out.println();
}

Alternatively, print g instead of f.

Just offered an alternate solution to the problem
Source Link
Usman Ismail
  • 18.8k
  • 14
  • 88
  • 165

Your program is entirely correct; all you need to change is the location of the print statement:

public static void main(String[] args) {
  int f = 0;
  int g = 1;

  for(int i = 1; i <= 10; i++)
  {
    System.out.print(f + " ");
    f = f + g;
    g = f - g;
  } 

  System.out.println();
}

//... or print g instead of f.

Your program is entirely correct; all you need to change is the location of the print statement:

public static void main(String[] args) {
  int f = 0;
  int g = 1;

  for(int i = 1; i <= 10; i++)
  {
    System.out.print(f + " ");
    f = f + g;
    g = f - g;
  } 

  System.out.println();
}

... or print g instead of f.

Your program is entirely correct; all you need to change is the location of the print statement:

public static void main(String[] args) {
  int f = 0;
  int g = 1;

  for(int i = 1; i <= 10; i++)
  {
    System.out.print(f + " ");
    f = f + g;
    g = f - g;
  } 

  System.out.println();
}

//... or print g instead of f.

Your program is entirely correct; all you need to change is the location of the print statement:

public static void main(String[] args) {
  int f = 0;
  int g = 1;

  for(int i = 1; i <= 10; i++)
  {
    System.out.print(f + " ");
    f = f + g;
    g = f - g;
  } 

  System.out.println();
}

... or print g instead of f.

Your program is entirely correct; all you need to change is the location of the print statement:

public static void main(String[] args) {
  int f = 0;
  int g = 1;

  for(int i = 1; i <= 10; i++)
  {
    System.out.print(f + " ");
    f = f + g;
    g = f - g;
  } 

  System.out.println();
}

Your program is entirely correct; all you need to change is the location of the print statement:

public static void main(String[] args) {
  int f = 0;
  int g = 1;

  for(int i = 1; i <= 10; i++)
  {
    System.out.print(f + " ");
    f = f + g;
    g = f - g;
  } 

  System.out.println();
}

... or print g instead of f.

Source Link
Marko Topolnik
  • 200.9k
  • 31
  • 336
  • 455
Loading