5 Replies Latest reply on Mar 19, 2018 7:28 PM by eudriscabrera-JavaNet

    help a first timer learn java :D

    Tafriel

      HI i am new here actually this is the first forum group i've ever been in. i started learning my first language yesterday (java) and i had this assignment for "loops" ;

      Let’s consider the folowing operations on a given integer:

      • if the number is divisible by 3, 4 is added to it;

      • if it is not, but is divisible by 4, it is divided by 2;

      • if it is divisible neither by 3 nor by 4, 1 is substracted from it.

      These operations are repeated successively until the result is zero. Concretely, if we start from an integer n0, the operations are applied to n0 which gives the number n1; then if n1 is different from zero, the operations are applied to n1 and son on, until we reach the number nk with value 0. For example if we start from 7, the following suite of number is generated: 6, 10, 9, 13, 12, 16, 8, 4, 2, 1 and0. The operations are repeated k = 11 times. If we start from 1, the value zero is immediately reached and the number of repetitions is then k = 1. You are asked to write a program which displays how many times the operations must be repeated until zero is reached. The number of repetitions must be displayed for any starting number comprised between two integers read from the keyboard. For example, for all starting numbers lying between 1 and 7, your program must produce the following output:

      1 -> 1

      2 -> 2

      3 -> 12

      4 -> 3

      5 -> 4

      6 -> 10

      7 -> 11

      --------------------------------------------------

      i wrote this and i had no execution pls help, dont know what have done wrong;

       

      public class suite {

         public static void main(String[] args) {

      int debut = 1 ;
      int fin = 7 ;
       
        for (int y = debut; y==fin ;y=y+1) {

      int i =y;

        int x = 0;

        while (i!=0) {

       

         if ((i % 3) == 0) { i = i+4; }

         else if (((i % 3) != 0) && ((i % 4) == 0 )) {i = i/2;}

         else{i=i-1;};

         }

        System.out.println(y+ "->" +x);
        ;
         }

        }

      }

       

       

      --------------------------

      THANKS