Make your own free website on Tripod.com

Sample Questions - Nested Loops (3 days)

What comes out?

1. for (x= 3; x>=1; x--)

      for (y=1; y <= 3; y++)

          System.out.print(y);

 

2. for (x=1; x <= 3; x++)

      for (y=x; y <= 4; y++)

          System.out.print(y);

 

3. for (x=1; x <= 3; x += 2)

       for (y=1;y <=4; y++)

          System.out.print(x);

 

4. for (x=1; x<= 5; x++)

        for (y=1; y<=4;y++)

           if (x % y==0)

             System.out.print(y);

 

5. for (x=5; x> = 1; x-=2)

        for (y=1; y <= x; y++)

          System.out.print(y);

 

6. for (a=1; a <= 2; a++)

      for (b=5; b >= 2; b--)

         System.out.print(b);

 

7. for (x=1 x <= 2; x++)

       for (y=1; y <= 7; y += 2)

            System.out.print(y);

 

8. for (x=1; x <= 5; x++)

       for (y=1; y <= x; y +=2)

         System.out.print(y);

 

9. sum = 0;

     for (x=1; x<=7 ; x++)

         for (y=1; y <= 3; y++)

            {sum += y;

           }

System.out.print(sum);

 

10. for (x=1; x <= 5; x++)

       {sum = 0;

           for (y=1; y <= 3; y++)

              sum += y;

           System.out.print(sum);  

        }

 

11. for (x= 1; x <= 25; x++)

       for (y=1; y <= 3; y++)

         sum += y;

  System.out.print(sum);

 

12. for (x=1; x <= 5; x++)

         for (y =2; y <= 7; y++)

          if (x==y)

             System.out.print(x);

 

13. sum = 0;

       for (x=1 ;x <= 4; x++)

          for (y=1; y <= 3; y++)

             sum += y;

  System.out.print(sum);

 

14. for (x=1; x <= 3; x++)

        {sum = 0;

         for (y=1; y <= 7; y+=2)

          sum += y;

        System.out.print(sum);

      }

 

15. for (x=1; x <= 6; x++)

         for (y=1; y <= x; y++)

             if (x % y==0)

               System.out.print(y);

 

16. for (x=1; x <= 3; x++)

        for (y=1; y <= 3; y++)

          System.out.print(x * y);

 

17. for (x=1; x <= 7; x += 2)

         for (y = 5; y >= 3; y--)

            if (y > x)

              System.out.print(y);

 

18. sum = 0;

 for (x=1; x <= 27; x++)

        for (y=1; y <= 6; y++)

          if (y % 2==0)

           sum += y;

       System.out.print( sum);

 

19. sum = 0;

        for (int x=1; x <= 678; x++)

            for (y=1; y <= 3; y++)

                sum += y;

    System.out.print(sum);

 

20.  for (int x=1; x <= 8; x++)

            for (int y= 2; y <= 7; y++)

                if (x % 2==0 && y % 3==0)

                    System.out.print(x +" "+ y); << endl;

 

21. Write a program which will print out all the outcomes when you roll a pair of dice.

 

22. Write a program that will tell you what the 2 numbers are that when multiplied together equals 255. When added together equals 32.

 

23.   Write a program that will tell you what the 2 numbers are that when multiplied together equals 608. When added together equals 31.

 

24. 3 numbers between -50 and 50 when multiplied together equals -11396. When added together equals -1.

 

25. Sue went to the store and bought saws (11.83), hammers (17.41) and pliers(14.81). She bouhght 16 items. If she spent 226.12 what did she buy.

 

26. Christal put lamps, couches and tables into storage. Altogether she placed 22 items in storage. If lamps weigh 17 pounds, couches 172 and tables 1213 and she placed 1369 total pounds in storage what did she store?

 

27. The first number is odd, the second is even. Together the three numbers add up to be 18. Multiplied together they equal 84. What are the possibilities.

 

28. Hamburgers cost .69, fries .89 and sodas 1.29. Joe bought 20 items and spent 19.20. What did he buy?

 

29. Print the factors of the first 100 numbers.

 

30. Print out the prime numbers between 1 and 1000.

 

31. The Volume of a rectangular prism is 672 cubic inches. What are possible dimensions. (whole numbers only)

 

32. John has 5.10 in quarters, dimes and nickels. If he has 31 coins what are possibilities?

 

33. Mary, Debbie and Sue are sisters. They are all younger than 30. Together their ages add up to be 74. Sue's age is an odd number. Mary's is even. Debbie is oldest. What are the possibilities?

 

34. 5x + 2y - 3z = 15.

        x, y and z are whole numbers between -5 and 5.

       Print out possibilities.

 

35. Write a program to print all the ways you can get 7 when you roll a pair of dice.

 

36. write a program that will tell you how many ways you can get 2, 3,4 or 5 when you roll a pair of dice? What % of the time would that be.

 

37. A circus has 33 birds and animals. There are 98 feet altogether. How many birds (two legged) and animals ( 4 legged) are there?

 

 

      

 

            

        

     

 

 

 

 

 

   

 


HOME