Javagony/Common programming problems in Javagony

Fibonacci numbers

edit

This is a recursive method in Javagony that returns the number in position n of the Fibonacci Sequence.

public class Fibonacci
{
   public static void main(String[] args)
   {
      System.out.println(fibo(10));
   }
   
   public static int fibo(int n)
   {
      try
      {
         int temp=1/n;
      }
      catch(Exception IO)
      {
         return 0;
      }
      
      try
      {
         int temp=1/(n-1);
      }
      catch(Exception IO)
      {
         return 1;
      }
      
      return fibo(n-1)+fibo(n-2);
   }
}

Fizz buzz

edit

This is a code in Javagony that prints all the numbers from 1 to 100, but instead of numbers that can be divided by 3, it will print “Fizz”, instead of numbers that can be divided by 5, it will print “Buzz”, and instead of numbers that can be divided by both 3 and 5, it will print “Fizz Buzz”:

public class Fizzbuzz
{
   public static void main(String[] args)
   {
      forFunction(1,101,1);
   }
   
   public static void forFunction(int firstNum,int lastNum,int step)
   {
      boolean fizz=firstNum%3==0;
      boolean buzz=firstNum%5==0;
      boolean fizzBuzz=fizz&&buzz;
      
      try
      {
         int temp=Boolean.compare(fizzBuzz,true);
         temp=1/temp;
         
         try
         {
            temp=Boolean.compare(fizz,true);
            temp=1/temp;
            
            try
            {
               temp=Boolean.compare(buzz,true);
               temp=1/temp;
               
               System.out.println(firstNum);
            }
            catch(Exception IO)
            {
               System.out.println("Buzz");
            }
         }
         catch(Exception IO)
         {
            System.out.println("Fizz");
         }
      }
      catch(Exception IO)
      {
         System.out.println("Fizz Buzz");
      }
      
      firstNum+=step;
      
      try
      {
         int temp=Math.addExact(firstNum+1,Integer.MAX_VALUE-lastNum);
         forFunction(firstNum,lastNum,step);
      }
      catch(Exception IO) {}
   }
}

Prime numbers

edit

This is a method in Javagony that gets a number and returns the boolean value true if it’s a prime number. Otherwise, it returns the boolean value false.

public class PrimeNumber
{
   public static void main(String[] args)
   {
      System.out.println(prime(7));
      System.out.println(prime(8));
   }
   
   public static boolean prime(int n)
   {
      try
      {
         int temp=1/(n-1);
      }
      catch(Exception IO)
      {
         return false;
      }
      
      return forFunction(2,n,1);
   }
   
   public static boolean forFunction(int firstNum,int lastNum,int step)
   {
      boolean b=lastNum%firstNum==0&&lastNum!=2;
      try
      {
         int temp=Boolean.compare(b,true);
         temp=1/temp;
      }
      catch(Exception IO)
      {
         return false;
      }
      
      firstNum+=step;
      
      try
      {
         int temp=Math.addExact(firstNum+1,Integer.MAX_VALUE-lastNum);
         return forFunction(firstNum,lastNum,step);
      }
      catch(Exception IO)
      {
         return true;
      }
   }
}