Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Go Programs
    • Python Programs
    • Java Programs

Java Assignment Operators

by suresh

The Java Assignment operators are used to assign the values to the declared variables. Equals ( = ) operator is the most commonly used assignment operator in Java. For example:

int i = 25;

The table below displays all the assignment operators present in the Java programming language.

Assignment OperatorsExampleExplanation
=x = 9Value 25 is assigned to x
+=x += 9This is same as x = x + 9
-=x -= 9This is same as x = x – 9
*=x *= 9This is same as x = x * 9
/=x /= 9This is same as x = x / 9
%=x %= 9This is same as x = x % 9

Java Assignment Operators example

In this Java Program, We are using two integer variables a and Sum. Next, we are going to use these two variables to show the working functionality of all the Assignment Operators in Java Programming Language

// Program for Java Assignment Operators 
package JavaOperators;

import java.util.Scanner;

public class AssignmentOperators {
	private static Scanner sc;
	public static void main(String[] args) {
		int a, Sum;
		sc = new Scanner(System.in);
		System.out.println(" Please Enter any integer Value: ");
		a = sc.nextInt();
		System.out.println(" Please Enter any integer Value for Total: ");
		Sum = sc.nextInt();
		
		System.out.format(" Value of Sum = %d \n", Sum += a );
		System.out.format(" Value of Sum = %d \n", Sum -= a );
		System.out.format(" Value of Sum = %d \n", Sum *= a );
		System.out.format(" Value of Sum = %d \n", Sum /= a );
		System.out.format(" Value of Sum = %d \n", Sum %= a );
	}
}
Java Assignment Operators 1

Within this Assignment Operators example, the following statement will ask the user to enter integer value . Next, in this Java Program, we are going to assign the user input value to integer variable a.

System.out.println(" Please Enter any integer Value: ");
a = sc.nextInt();

The following Java statement will ask the user to enter the integer value Sum. And then, we are going to assign the user input value to the integer variable Sum.

System.out.println(" Please Enter any integer Value for Total: ");
Sum = sc.nextInt();

Next line, we performed all the assignment operations on a and Sum variables using available assignment operators. Let us see the functionality of the Java Assignment Operators

System.out.format(" Value of Sum = %d \n", Sum += a );

Sum += a means

Sum = Sum + a ==> 25 + 4 = 29

System.out.format(" Value of Sum = %d \n", Sum -= a );

Sum -= a means

Sum = Sum – a ==> 29 – 4 = 25

System.out.format(" Value of Sum = %d \n", Sum *= a );

Sum *= a means

Sum = Sum * a ==> 25 * 4 = 100

System.out.format(" Value of Sum = %d \n", Sum /= a );

Sum /= a means

Sum = Sum / a ==> 100 / 4 = 25

System.out.format(" Value of Sum = %d \n", Sum %= a );

Sum %= a means

Sum = Sum % a ==> 25 % 4 = 1 (Remainder of 25 / 4 is = 1)

Placed Under: Java

  • SQL DML, DDL, DCL & TCL Cmds
  • SQL NOT EXISTS Operator
  • SQL UPDATE from SELECT
  • SQL AFTER UPDATE Triggers
  • SQL Get Column Names in Table
  • SQL IF ELSE
  • SQL ACID Properties
  • SQL FOR XML PATH
  • Java Two Dimensional Array
  • Java Perfect Number Program
  • Java Count Digits in a Number
  • C Compare Two Strings Program
  • C Print Prime Numbers 1 to 100
  • C program to Reverse a String
  • C Palindrome Number Program
  • C Program for Palindrome String
  • C Remove Duplicate String Chars
  • C Square of a Number Program
  • C Sum and Average of N Number
  • Python Fibonacci Series program
  • Python Area Of Circle Program
  • Python Prime Numbers 1 to 100
  • Python Program for Leap Year
  • Tableau Rank Calculation
  • Tableau Google Maps usage
  • Power BI Format Dates
  • Power BI Top 10 Filters
  • Power BI – Create Hierarchy
  • Power BI DAX Math Functions
  • Learn SSIS in 28 Days
  • SSIS Transformations
  • SSIS Incremental Load
  • SSRS Drill Through Reports
  • SSRS Drill Down Reports
  • R Programming Tutorial

Copyright © 2021 · All Rights Reserved by Suresh

About Us | Contact Us | Privacy Policy