This is an example of assignment operator.
** If you copy it ,ignore package.** Remind this is a practice program .
Source Code:
- package basicjava;
- //import java.util.Scanner;
- public class AssinmentDemo {
- public static void main(String[] args) {
- // Scanner input = new Scanner(System.in);
- int x = 3,y = 2;
- /* System.out.printf("Enter the number of x:");
- x = input.nextInt();
- System.out.printf("Enter the number of y:");
- y = input.nextInt();*/
- x += y; //x = x + y = 5
- System.out.println("1.ans is ="+x);
- x -= y; //x = x - y = 3
- System.out.println("2.ans is ="+x);
- x *= y; //x = x * y = 6
- System.out.println("3.ans is ="+x);
- x /= y; //x = x / y = 3
- System.out.println("4.ans is ="+x);
- x %= y; //x = x % y = 1
- System.out.println("4.ans is ="+x);
- }
- }
Output:
1.ans is =52.ans is =33.ans is =64.ans is =34.ans is =1
0 comments:
Post a Comment