Jump to content


Check out our Community Blogs

Ritwik I the programmer

Member Since 01 Aug 2011
Offline Last Active May 30 2016 10:55 PM
*****

Posts I've Made

In Topic: Nested For Loop [EXAMPLES!]

05 July 2014 - 07:27 PM

In fact, although there is a pattern, the line starting with 0 is deleted to avoid -ve nos. So, the general pattern would have been,

0  -1 -2 -3 -4
1   2  3  4  5
10  9  8  7  6
11 12 13 14 15
20 19 18 17 16
21 22 23 24 25

So, you start with 0, increment your variable i by 10 in each iteration, and print lines starting with i and i + 1, except when loop variable is 0. I think you can figure out how to do the individual lines and translate this into code.


In Topic: Methods

04 July 2014 - 10:22 PM

JVM would not, by itself, specifically create an instance of any class unless the code written by the programmer tells it to(at least, not any instances that you need to bother about). A main() function, if not static, would be regarded as just another method, not THE main() function from which execution of a program starts.


In Topic: Nested For Loop [EXAMPLES!]

04 July 2014 - 08:26 PM

There are infinite possible pattern variations that can be set as assignments, so it is not very surprising that you can't find the exact solutions here. As I see, you are currently worrying about 3 patterns

 

1.

1
2, 1
1, 2, 3
4, 3, 2, 1
1, 2, 3, 4, 5

2.

-----*-----
----***----
---*****---
--*******--
-*********-
***********
-*********-
--*******--
---*****---
----***----
-----*-----

3.

2, 4, 6, 8
4, 6, 8
6, 8
8

First, 2 things that are not about the patterns:

1.To avoid the comma on the last item, check to see if this is the last iteration. For eg.

for(int i = 0; i < 10; i++)

In the above code, the loop body is executed for the last time when i = 9. So:

for(int i = 0; i < 10; i++)
{
    //Code for printing pattern
    if(i != 9)
        System.out.print(",")
}

2.Try using tabs instead of space when printing patterns. It simplifies the spacing concerns when there are 2-3 digit numbers in the pattern.

 

Now about the patterns:

 

1.If a pattern seems too complex on the whole, break it down into parts. For example, the diamond pattern. Break it down into the upper and lower triangle. Then, thing how to print the dashes and stars with separate inner loops. Count the number of dashes and stars on each line and see what separate patterns they follow. Then bring it together.

 

2.It seems you are having trouble thinking about loops that decrement loop variables. For example, see this one

4, 3, 2, 1
3, 2, 1
2, 1,
1

Here's the code for this:

for(int i = 4; i >= 1; i--)
{
    for(int j = i; j >= 1; j--)
    {
        System.out.print(j);
        if(j != 1)
            System.out.print(",");
    }
    System.out.println();
}

Now try thinking about how you would do the 3rd problem.

 

3.Now, again, try breaking down the 1st problem. As you see, the odd and even lines follow different patterns. What patterns? How can you implement them separately using inner loops?

 

Hint:You need separate inner loops for the odd and even lines. Obviously, one of them should be executed only for odd line numbers and the other for even ones. So, you need to put them inside if-else blocks.


In Topic: Hi

30 June 2014 - 06:02 AM

Welcome to Codecall! :thumbup1:


In Topic: List of simple Java games

24 June 2014 - 05:52 AM

About sir, I don't think i quite qualify for that title. As for making games, you can think of creating software versions of popular board games and stuff(like chess, tic-tac-toe, etc.) as well as existing video games, although how that would turn out as a thesis I have no idea. For other stuff, some ideas are a personal notes and reminders manager, calender, Graph drawers for functions, etc. If you are trying to create something new, try giving twists to known games, like 3/4 player tic-tac-toe with larger fields, snake with power ups and foods of different types, etc. You could even try for role-playing games of mario type, depending on experience. For an experience of how to code a basic game interface, try this code:

Attached File  Snake 3.0.rar   573.69KB   1887 downloads

I would suggest using Netbeans IDE's form editor to create your UIs. Making swing put things exactly where you want to can be really difficult at times.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download