Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Random;
- import java.util.*;
- public class Main {
- public static void main(String[] args) {
- //This program is showing the different variable types
- //Printing to screen
- System.out.println("My name is Mr Doyle");
- //Printing a number
- System.out.println(56);
- //Printing a Boolean
- System.out.println(true);
- //Printing a character
- System.out.println('@');
- //Assigning a value to a variable
- int myLuckyNumber = 7;
- System.out.println("My lucky number is: " + myLuckyNumber);
- //variable review
- int myNumber = 42;
- boolean isFun = true;
- char movieRating = 'A';
- //Whitespace is not compiled by Java
- //Single line comment
- /*
- Multiline comment
- */
- //Using operators
- int sum = 34 + 113;
- int difference = 91 - 205;
- int product = 2 * 8;
- int quotient = 45 / 3;
- System.out.println(sum);
- System.out.println("My difference is: " + difference);
- System.out.println("My product is " + product + ", and my quotient is " + quotient);
- //Modulo
- int myRemainder = 34 % 8;
- System.out.println("The remainder of 34 / 8 is " + myRemainder);
- //Relation operators
- System.out.println("Is 6 < 9?");
- System.out.println(6 < 9);
- System.out.println("Is 6 > 9?");
- System.out.println(6 > 9);
- //Checking the equality of data (use == to compare values, and use = to set values)
- char myChar = 'A';
- int myInt = -2;
- System.out.println("Checking if A = -2");
- System.out.println(myChar==myInt); //should print false
- //summary of concepts so far
- boolean isComplete = true;
- int awesomeLevel = 121;
- int epicLevel = awesomeLevel * 2;
- System.out.println(epicLevel);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement