72 thoughts on “An online Java Compiler

  1. Write a function that returns an array of all elements of the natural numbers in order from first to last print.

    plz answer it with java and instantly

    1. There are infinity natural numbers, but this will print the first n;

      import java.lang.*;
      public class PrintNaturals {
      const int n = 10; //substitute 10 for anything!
      public static void main(String[] args)
      {
      int[n] naturals; //array of natural numbers
      for (int i = 0; i < n; i ++)
      {
      naturals[i] = i + 1;
      }
      //Now you have an array of natural numbers, now let's print it
      for (int i = 0; i < n; i ++)
      {
      System.out.print((String)naturals[i]);
      }
      }
      }

Leave a Comment

Your email address will not be published. Required fields are marked *