Advertisement
wingman007

Java2014_DataTypesOperatorsConsole

Nov 8th, 2014
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.78 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6.  
  7. package datatypes;
  8.  
  9. import java.io.IOException;
  10. import java.util.*;
  11.  
  12. /**
  13.  *
  14.  * @author fmi
  15.  */
  16. public class DataTypes {
  17.  
  18.     /**
  19.      * @param args the command line arguments
  20.      */
  21.     public static void main(String[] args) throws IOException {
  22.         // TODO code application logic here
  23.         byte myByte = 22;
  24.         short myShort = 257;
  25.         int myInt = -123;
  26.         long myLong = 123L; // 077 0x077
  27.        
  28.         float myFloat = 2.34F;
  29.         double myDouble = 2.34; //
  30.        
  31.         char myChar = 'c'; //'\u0000'
  32.         boolean myBoolean = false; // true
  33.        
  34.         // -------------------- Referent -----
  35.         String myName = "Stoyan\\ "; // \n
  36.         Object myOtherByte = 3;
  37.        
  38.         System.out.print(myName);
  39.         System.out.println(myName);
  40.        
  41.         // int ch;
  42.         // 1.
  43.         // ch = System.in.read();
  44.        // System.out.print((char) ch);
  45.        
  46.         // while ((ch = System.in.read()) != '\n') {
  47.         //    System.out.print((char) ch);
  48.         // }
  49.        
  50.         // 2.
  51.         Scanner input = new Scanner(System.in);
  52.         System.out.print("Please enter your first name: ");
  53.         String firstName = input.nextLine();
  54.         System.out.println(firstName);
  55.        
  56.         double number1 = 3.14;
  57.         double number2 = 2.71;
  58.        
  59.         System.out.println(number1 + number2);
  60.        
  61.         System.out.printf("%.3f \n", number1 + number2);
  62.        
  63. /* Old way for reading symbols
  64.         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  65.         String firstString = br.readLine();
  66.         String lastString = br.readLine();
  67.         System.out.printf("Hello, %s %s!\n", firstString, lastString);
  68. */
  69.  
  70.  
  71.       for(int i = 0; i < 10; i++)
  72.       {
  73.           for (int j = 0; j < i; j ++)
  74.           {
  75.             System.out.print('*');
  76.           }
  77.           System.out.print("\n");
  78.       }
  79.      
  80.       Operations(2.32, 45.6);
  81.      
  82.     }
  83.    
  84.     static void Operations(double par1, double par2)
  85.     {
  86.         System.out.printf("%.2f + %.2f = %.2f", par1, par2, par1 + par2);
  87.        
  88.     }
  89.    
  90. }
  91.  
  92. /*
  93. import java.util.*;
  94. public class ReadingStringsNewStyle {
  95. public static void main(String[] args) {
  96. Scanner input = new Scanner(System.in);
  97. System.out.print("Please enter your first name: ");
  98. String firstName = input.nextLine();
  99. System.out.print("Please enter your last name: ");
  100. String lastName = input.nextLine();
  101. System.out.printf("Hello, %s %s!\n", firstName, lastName);
  102. // input.close(); - Don't close Scanner reading System.in!
  103. }
  104. }
  105. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement