• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.

Archived

This topic is now archived and is closed to further replies.

Fabricant

[java] Need help

12 posts in this topic

Hi I wrote this program : class elseif { public static void main(String args[]) { int x=2, y=3, z=4; if(x == 2 && y <= 3) { System.out.println("true!"); } else { System.out.println("false!"); } if(x == 2 || y != 2 && z * z >= 16) { System.out.println("true!"); } else { System.out.println("false!"); } if(y == 3 && !(z == 1)) { System.out.println("true!"); } else { System.out.println("false!"); } if(x != 2 && y > 3) { System.out.println("true!"); } else { System.out.println("false!"); } if(x < y || x > z) { System.out.println("true!"); } else { System.out.println("false!"); } } } > My Question : Why does the code below not work (it shows no answers). It would be a lot easier to write >like I did below. Thanks for help ! class elseif { public static void main(String args[]) { int x=2, y=3, z=4; if(x == 2 && y <= 3) if(x == 2 || y != 2 && z * z >= 16) if(y == 3 && !(z == 1)) if(x != 2 && y > 3) if(x < y || x > z) { System.out.println("true!"); } else { System.out.println("false!"); } } }
0

Share this post


Link to post
Share on other sites
  
if(x == 2 && y <= 3)
if(x == 2 || y != 2 && z * z >= 16)
if(y == 3 && !(z == 1))
if(x != 2 && y > 3)
if(x < y || x > z){
System.out.println("true!");
}
else{
System.out.println("false!");
}



That''s what your code essentially is read as. The first if, x has to equal 2, whereas to even display an answer, x cannot equal 2.
0

Share this post


Link to post
Share on other sites
I can think of three different ways you might mean... First, you might mean "if all conditionals are true, print true," second, you might mean "if any conditional is true, print true,", or third, which is probably what you want, "for each conditional, print true if it is true."

Here''s a bit of sample code based on how I''d do the third case, which is what I think you mean, based on your first example:

  
public class ElseIf
{
public static void main(String [] args)
{
int x=2, y=3, z=4;

test(x == 2 && y ==3);
test(x == 2 || y != 2 && z * z >= 16);
test(y == 3 && !(z == 1));
test(x != 2 && y > 3);
test(x < y || x > z);
} //main


public static void test(boolean b)
{
if (b) System.out.println("true!");
else System.out.println("false!");
} //test


} //class ElseIf



I''d guess, from your questions, that you''re quite new to java programming, possibly taking a class or doing some tutorials from a book. Either way, I''m probably jumping ahead of what you''re "supposed" to know by including a seperate function to simplify the process.

I''d say more important is Nytegard''s demonstration. It shows how the compiler is interpreting the code you''re entering. It treats each if as nested inside the previous... That is, if the last check was true, check this now. In order for something to print in the code you''ve got, every step except the last one would have to be true. Otherwise, it will never make it to the innermost if...else which contains the System.out.println calls.

I''d suggest checking out some web-based java resources to increase your general knowledge of things like this. Bruce Eckel''s Thinking in Java is a good place to start. It starts slow for those with no experience, but also has a lot of in-depth info that is useful once you get some experience. It is at this URL:

http://gothix.trans4media.com/docs/tij/Contents.html

I also suggest downloading Sun''s Java 2 API specification from java.sun.com, if you haven''t already, as it is pretty good documentation of how to use the basic library functions provided with the language.
0

Share this post


Link to post
Share on other sites
thanks for the help. I'm new to Java and still learning. I think Java is a good base to learn C later. Thanks for the help !

Edited by - Fabricant on January 5, 2001 1:12:14 PM
0

Share this post


Link to post
Share on other sites
The sun java site is a bit confusing. I already downloaded the full java 2 1.3 SDK but I can''t find an offline documentation. There''s a 23 megs big html SDK doc but I dont think its the right file.
0

Share this post


Link to post
Share on other sites
That 23 meg''er is the sdk doc. You wouldn''t think it would be so large but there it is. Takes for ever and a day to download on a 56k when a new JDK comes out. I usually have it on my gaming machine while I work on the dev machine. What was life like before I had two machines? Very helpful.

I wanrned you! Didn''t I warn you?! That colored chalk was forged by Lucifer himself!

Opere Citato
0

Share this post


Link to post
Share on other sites
thanks GKW

c_wraith :

is there an offline doc for the link you gave me (http://gothix.trans4media.com/docs/tij/Contents.html)
because I cannot be online all the time.
0

Share this post


Link to post
Share on other sites
I''m sorry... I don''t know of an offline version of that. But, it shouldn''t be too hard to just download and save the first few chapters. As I recall, it isn''t that big a book.
0

Share this post


Link to post
Share on other sites
quote:
Original post by Fabricant

thanks GKW

c_wraith :

is there an offline doc for the link you gave me (http://gothix.trans4media.com/docs/tij/Contents.html)
because I cannot be online all the time.


Go to the official Thinking in Java homepage and you can get it all: off-line (pdk, thml, word, etc.), printed version and on-line version.

http://www.bruceeckel.com/TIJ2/index.html

Jacob Marner

0

Share this post


Link to post
Share on other sites
"I think Java is a good base to learn C later."

I _don''t_ think Java is a good base for learning C. They are different. While they look alike on the surface, they can behave quite differently.

C is meant to give you a lot of power (access to the machine).

Java is meant to be safe and portable.
0

Share this post


Link to post
Share on other sites
If you''re interested in the JDK-1.2.2 API documentation for offline reading I have put it out here:
http://gothix.trans4media.com/docs/jdk1.2.2-doc.tar.gz

As you can see it''s a Unix-tarball, so if you''re on a Windows-machine (or, heaven forbid, a Mac), let me know, and I''ll put a "regular" zip-version there as well.

Neophyte

- Death awaits you all with nasty, big, pointy teeth. -
0

Share this post


Link to post
Share on other sites