Java1

First java program
mail@pastecode.io avatar
unknown
java
2 years ago
3.7 kB
7
Indexable
Never
package com.sai.datastructures;

// library import
import java.util.Scanner;

// Class declaration
public class Prakash {

    // main method or function, starting point of program execution
    public static void main(String[] args) {
        System.out.println("Hello Prakash");


        // Data types
        // int - integer
        // long - big values
        // double/float -> floating point numbers
        // char - character - single character ('a', 'b', 'c')
        // String - "prakash", "sai"


        // Variable declaration
        // datatype variableName = some value;

        // Integer example

        /* another way

         of declaring comments

         */

        int a = 10;
        char c = 'A';
        double d = 5.00005;
        float f = 10.2f;
        long l = 1111111111111l;
        String s = "Sai krishna";

        System.out.println("Integer - ->>>>>>" + a);
        System.out.println("Long - " + l);
        System.out.println("Char - " + c);
        System.out.println("Double - " + d);
        System.out.println("Float - " + f);
        System.out.println("String " + s);

        // Reading the input dynamically

      /*  Scanner sc = new Scanner(System.in);

        System.out.println("Enter an integer value : ");
        int x = sc.nextInt();

        System.out.println("Enter an long value : ");
        long y = sc.nextLong();

        System.out.println("Enter an double value : ");
        double z = sc.nextDouble();

        System.out.println("Enter an String value : ");
        String str = sc.next();

        System.out.println("Integer " + x + "\nLong " + y + "\n Double " + z + "String : " + str);
*/

        // Arithmetic operators

        int num1 = 100;
        int num2 = 20;
        int sum = num1 + num2;

        System.out.println("num1 + num2: " + sum );
        System.out.println("num1 - num2: " + (num1 - num2) );
        System.out.println("num1 * num2: " + (num1 * num2) );
        System.out.println("num1 / num2: " + (num1 / num2) );
        System.out.println("num1 % num2: " + (num1 % num2) );

        // Assignment Operators

        num1 += 10; // num1 = num1 + 10;
        num2 -= 10; // num1 = num1 + 10;
        num1 *= 10; // num1 = num1 + 10;
        num1 /= 10; // num1 = num1 + 10;

        // increment and decrement

        System.out.println("\n\n Increment decrement operation");

        int number = 1;

        System.out.println("Post increment " + number++);
        System.out.println("After increment " + number);
        num1++; // post increment System.out.println(num1++); // prints 100
        num1--; // post decrement

        System.out.println("Pre increment " + ++number);
        System.out.println("After increment " + number);
        ++num1; // pre increment - System.out.println(++num1); // prints 101
        --num1; // pre decrement

        // Logical operators

        boolean b1 = true;
        boolean b2 = false;

        System.out.println("b1 && b2: " + (b1&&b2));
        System.out.println("b1 || b2: " + (b1||b2));
        System.out.println("!(b1 && b2): " + !(b1&&b2));

        // comparision operators

        int p = 1;
        int q = 2;

        System.out.println(p == q);
        System.out.println(p != q);
        System.out.println(p > q);
        System.out.println(p < q);
        System.out.println(p <= q);
        System.out.println(p >= q);
        
        // Bitwise operators - TODO

        /*
           JVM
           Java Uses // yet to study
           Java class declaration, main method
           Variables and data types
           Dynamic input reading
           Operators
         */
    }
}