java cheatsheet

Download Java Cheatsheet

Post on 24-Oct-2014

71 views

Category:

Documents

1 download

Embed Size (px)

TRANSCRIPT

Visit: ProgrammingKid.com

Java Programming Cheat SheetHello, World.

Editing, compiling, and executing.

Built-in data types.

Courtesy : Robert Sedgewick and Kevin Wayne. Copyright 2007. All rights reserved

Visit: ProgrammingKid.com

Declaration and assignment statements.

Integers.

Courtesy : Robert Sedgewick and Kevin Wayne. Copyright 2007. All rights reserved

Visit: ProgrammingKid.com

Floating point numbers.

Booleans.

Courtesy : Robert Sedgewick and Kevin Wayne. Copyright 2007. All rights reserved

Visit: ProgrammingKid.com

Comparison operators.

Math library.

Command-line arguments.

Courtesy : Robert Sedgewick and Kevin Wayne. Copyright 2007. All rights reserved

Visit: ProgrammingKid.com int a = Integer.parseInt(args[0]); double b = Double.parseDouble(args[1]); String c = args[2]; // read int from command-line // read double from command-line // read String from command-line

Type conversion.

If and if-else statements.

Courtesy : Robert Sedgewick and Kevin Wayne. Copyright 2007. All rights reserved

Visit: ProgrammingKid.com

Nested if-else statement.

While and for loops.

Nested for loops. If-else nested inside a while loop.// how many fair bets until you go broke? int bets = 0; while (stake > 0) { bets++; if (Math.random() < 0.5) stake++; else stake--; }

Courtesy : Robert Sedgewick and Kevin Wayne. Copyright 2007. All rights reserved

Visit: ProgrammingKid.com

Deeper nesting.// print out Pythagorean triples (i, j, k) such that i^2 + j^2 = k^2 for (int i = 1; i