0% found this document useful (0 votes)
52 views

Java Cheat Sheet

The document discusses code formatting, adding imports, and defining variables in Java code. It then provides steps for formatting code with line numbers and collaborating to output "Hello World". It lists challenges for beginner, intermediate, and advanced levels including a game plan, commenting code, and a Java quiz. It also includes a simple "Hello World" Java program that takes user input using a Scanner variable.

Uploaded by

d_sheps
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
52 views

Java Cheat Sheet

The document discusses code formatting, adding imports, and defining variables in Java code. It then provides steps for formatting code with line numbers and collaborating to output "Hello World". It lists challenges for beginner, intermediate, and advanced levels including a game plan, commenting code, and a Java quiz. It also includes a simple "Hello World" Java program that takes user input using a Scanner variable.

Uploaded by

d_sheps
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

f Formats code

O adds imports
Variables:
String myString;
int myInteger;
float myDecimal;
Learn to what would happen with code: addVal++; addVal +=3;
H e l l o W o r l d
S t e p 0 ) M a k e s u r e w e a r e s a v i n g t o t h e r i g h t p l a c e

S t e p 1 ) T u r n o n l i n e n u m b e r s .
R i g h t c l i c k t h e g u t t e r a n d s e l e c t " S h o w L i n e N u m b e r s "

S t e p 2 ) H e l l o W o r l d t o g e t h e r ( W e a l l w o r k t o g e t h e r ! )

B e g i n n e r L e v e l ) H e l l o D u n g e o n ( i D T e c h G a m e P l a n )
A d v a n c e d L e v e l ) C o m m e n t C o d e a n d i n c l u d e t e x t a r t f r o m p a t o r j k . c o m / s o f t w a r e / t a a g / i n c o d e a n d / o r i n t h e u s e r w e l c o m e
I n t e r m e d i a t e L e v e l ) S e e i f y o u c a n c o m p l e t e t h e n D y n o D u n g e o n : D o o m e d E n t r a n c e C h a l l e n g e
E l i t e ) S t a r t w o r k i n g o n t h e g e t t i n g s t a r t e d w i t h J a v a Q u i z l e t C h a l l e n g e t y p i n g i n r e q u i r e d c o d e a s f a s t a s p o s s i b l e w i t h o u t a n y
e r r o r s ! h t t p : / / q u i z l e t . c o m / _ q u m w o
/ / T h i s i s m y f i r s t p r o g r a m
/ * I t i s c o o l * /

p u b l i c c l a s s H e l l o W o r l d {

p u b l i c s t a t i c v o i d m a i n ( S t r i n g [ ] a r g s ) {
S y s t e m . o u t . p r i n t l n ( " H e l l o W o r l d " ) ;
S y s t e m . o u t . p r i n t l n ( " \ n " ) ;

} / / m a i n
} / / c l a s s
R u n s y o u r p r o g r a m
+ + s y s o u t
import java.util.Scanner;

// This program takes user input
/* It is awesome
* It uses variables
* and a scanner to allow user input */

public class HelloWorld {

public static void main(String[] args) {
System.out.println("Hello World");

Scanner input = new Scanner(System.in);
String userName;
userName = input.nextLine();

System.out.println("Welcome " + userName);

input.close();

} // main
} // class
To convert a string into an int, use:
String str = "1234";
int num = Integer.parseInt(str);
To convert a number into a string, use:
int num = 1234;
String str = String.valueOf(num);

You might also like