This is an example of assignment operator. 



** If you copy it ,ignore package.** Remind this is a practice program .

Source Code:

  1. package basicjava;
  2. //import java.util.Scanner;
  3. public class AssinmentDemo {
  4. public static void main(String[] args) {
  5. // Scanner input = new Scanner(System.in);
  6. int x = 3,y = 2;
  7. /* System.out.printf("Enter the number of x:");
  8. x = input.nextInt();
  9. System.out.printf("Enter the number of y:");
  10. y = input.nextInt();*/
  11. x += y;   //x = x + y = 5
  12. System.out.println("1.ans is ="+x);
  13. x -= y;    //x = x - y = 3
  14. System.out.println("2.ans is ="+x);
  15. x *= y;    //x = x * y = 6
  16. System.out.println("3.ans is ="+x);
  17. x /= y;   //x = x / y = 3
  18. System.out.println("4.ans is ="+x);
  19. x %= y;   //x = x % y = 1
  20. System.out.println("4.ans is ="+x);
  21. }
  22. }

Output:

1.ans is =5
2.ans is =3
3.ans is =6
4.ans is =3
4.ans is =1

0 comments:

Post a Comment