Java Program2

/* Java program by Zac J. (c) 2015 spaceedge.com
Simple Fibonacci Sequence
*/
public class Program2
{
public static void main(String[] args)
{
System.out.println(“Simple Fibonacci Sequence! \n”);
int x=0, x1=0, x2=1;
for (int i = 0; i <= 20; i++) {
System.out.printf(“%2d:  x=%-20s \n”, i, x);
x1 = x; x = x1 + x2; x2 = x1;
}//System.out.println( i + “: \t x=” + x);
}
}

To run program compile: javac Program2.java
Then run the class with:   java Program2

 

Java Program1

// Java Program1.
public class Program1
{
public static void main(String[] args)
{
System.out.println(“Hello, loop i to 5, x=i+5! \n”);
for (int i = 0; i <= 5; i++) {
int x = 5 + i;
System.out.println(“i=” + i + “, x=i+5=” + x);
}
}
}

To run program compile: javac Program1.java
Then run the class with:  java Program1

 

If you get the following error:

‘javac’ is not recognized as an internal or external command.

 

From windows cmd enter this command:

set path=C:\Program Files\Java\jdk1.8.0_65\bin;
SHARE ON