Advertisement
MrDoyle

intro to java

Aug 17th, 2020 (edited)
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.92 KB | None | 0 0
  1. public class Main {
  2.  
  3.     public static void main(String[] args) {
  4.         //This program is showing the different variable types
  5.  
  6.         //Printing to screen
  7.         System.out.println("My name is Mr Doyle");
  8.  
  9.         //Printing a number
  10.         System.out.println(56);
  11.  
  12.         //Printing a Boolean
  13.         System.out.println(true);
  14.  
  15.         //Printing a character
  16.         System.out.println('@');
  17.  
  18.         //Assigning a value to a variable
  19.         int myLuckyNumber = 7;
  20.         System.out.println("My lucky number is: " + myLuckyNumber);
  21.  
  22.         //variable review
  23.         int myNumber = 42;
  24.         boolean isFun = true;
  25.         char movieRating = 'A';
  26.  
  27.         //Whitespace       is      not     compiled  by Java
  28.  
  29.         //Single line comment
  30.         /*
  31.  
  32.         Multiline comment
  33.  
  34.          */
  35.  
  36.         //Using operators
  37.         int sum = 34 + 113;
  38.         int difference = 91 - 205;
  39.         int product = 2 * 8;
  40.         int quotient = 45 / 3;
  41.         System.out.println(sum);
  42.         System.out.println("My difference is: " + difference);
  43.         System.out.println("My product is " + product + ", and my quotient is " + quotient);
  44.  
  45.         //Modulo
  46.         int myRemainder = 34 % 8;
  47.         System.out.println("The remainder of 34 / 8 is " + myRemainder);
  48.  
  49.         //Relation operators
  50.         System.out.println("Is 6 < 9?");
  51.         System.out.println(6 < 9);
  52.  
  53.         System.out.println("Is 6 > 9?");
  54.         System.out.println(6 > 9);
  55.  
  56.         //Checking the equality of data (use == to compare values, and use = to set values)
  57.         char myChar = 'A';
  58.         int myInt = -2;
  59.         System.out.println("Checking if A = -2");
  60.         System.out.println(myChar==myInt); //should print false
  61.  
  62.         //summary of concepts so far
  63.         boolean isComplete = true;
  64.         int awesomeLevel = 121;
  65.         int epicLevel = awesomeLevel * 2;
  66.         System.out.println(epicLevel);
  67.  
  68.     }
  69. }
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement