0% found this document useful (0 votes)
0 views10 pages

Java

The document provides a series of Java programs demonstrating the use of various operators, including arithmetic, assignment, relational, logical, increment, and decrement operators. Each program includes code snippets and their corresponding output, showcasing how to perform operations such as addition, subtraction, and user input handling using the Scanner class. Overall, it serves as a practical guide for understanding and implementing basic data operations in Java.

Uploaded by

doyitadeshna
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views10 pages

Java

The document provides a series of Java programs demonstrating the use of various operators, including arithmetic, assignment, relational, logical, increment, and decrement operators. Each program includes code snippets and their corresponding output, showcasing how to perform operations such as addition, subtraction, and user input handling using the Scanner class. Overall, it serves as a practical guide for understanding and implementing basic data operations in Java.

Uploaded by

doyitadeshna
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Chapter-4 STORING & OPERATING ON DATA

[Link] a program in java using Arithmetic operator.

public class ArithmeticOperator


{
public static void main(String[] args)
{
double number1 = 12.5, number2 = 3.5, result;

result = number1 + number2; // Using addition operator


[Link]("number1 + number2 = " + result);

result = number1 - number2; // Using subtraction operator


[Link]("number1 - number2 = " + result);

result = number1 * number2; // Using multiplication operator


[Link]("number1 * number2 = " + result);

result = number1 / number2; // Using division operator


[Link]("number1 / number2 = " + result);

result = number1 % number2; // Using remainder operator


[Link]("number1 % number2 = " + result);
}
}
Output:
number1 + number2 = 16.0
number1 - number2 = 9.0
number1 * number2 = 43.75
number1 / number2 = 3.5714285714285716
number1 % number2 = 2.0
Chapter-4 STORING & OPERATING ON DATA
[Link] a program in java using Assignment operator.
public class Assignment
{
public static void main(String[] args)
{
int x = 10;
[Link](x);
}
}
Output:
10

[Link] a program in java using Addition Assignment operator.


public class Addition_Assignment
{
public static void main(String[] args)
{
int x = 10;
x += 5;
[Link](x);
}
}
Output:
15

[Link] a program in java using Subtract Assignment operator.

public class Subtract_Assignment


{
public static void main(String[] args)
{
int x = 5;
x -= 3;
[Link](x);
Chapter-4 STORING & OPERATING ON DATA
}
}
Output:
2

[Link] a program in java using Multiply Assignment operator.


public class Multiply_Assignment
{
public static void main(String[] args)
{
int x = 5;
x *= 3;
[Link](x);
}
}
Output:
15

[Link] a program in java using Division Assignment operator.

public class Division_Assignment


{
public static void main(String[] args)
{
double x = 5;
x /= 3;
[Link](x);
}
}
Output:
1.6666666666666667
Chapter-4 STORING & OPERATING ON DATA
[Link] a program in java using Modulo_ Assignment operator.

public class Modulo_Assignment


{
public static void main(String[] args)
{
int x = 5;
x %= 3;
[Link](x);
}
}
Output:
2

[Link] a program in java using Relational operator (equal to).

public class MyClass


{
public static void main(String[] args)
{
int x = 5;
int y = 3;
[Link](x == y); // returns false because 5 is not equal to 3
}
}
Output:
False

[Link] a program in java using Relational operator (not equal to).

public class MyClass


{
public static void main(String[] args)
{
int x = 5;
Chapter-4 STORING & OPERATING ON DATA
int y = 3;
[Link](x != y); // returns true because 5 is not equal to 3
}
}
Output:
True

[Link] a program in java using Relational operator (greater than).

public class MyClass


{
public static void main(String[] args)
{
int x = 5;
int y = 3;
[Link](x > y); // returns true because 5 is greater than 3
}
}
Output:
True

[Link] a program in java using Relational operator (greater than equal to).

public class MyClass


{
public static void main(String[] args)
{
int x = 5;
int y = 3;
[Link](x >= y); // returns true because 5 is greater, or equal, to 3
}
}
Output:
True
Chapter-4 STORING & OPERATING ON DATA

[Link] a program in java using Relational operator (less than).

public class MyClass


{
public static void main(String[] args)
{
int x = 5;
int y = 3;
[Link](x < y); // returns false because 5 is not less than 3
}
}
Output:
False

[Link] a program in java using Relational operator (less than equal to).

public class MyClass


{
public static void main(String[] args)
{
int x = 5;
int y = 3;
[Link](x <= y); // returns false because 5 is neither less than or equal to 3
}
}
Output:
False

[Link] a program in java using Logical operator (logical AND).

public class MyClass


{
public static void main(String[] args)
Chapter-4 STORING & OPERATING ON DATA
{
int x = 5;
[Link](x > 3 && x < 10); // returns true because 5 is greater than 3 AND 5 is
less than 10
}
}
Output:
True

[Link] a program in java using Logical operator (logical OR).

public class MyClass


{
public static void main(String[] args)
{
int x = 5;
[Link](x > 3 || x < 4);
// returns true because one of the conditions are true (5 is greater than 3, but 5 is not less
than 4)
}
}
Output:
True

[Link] a program in java using Logical operator (logical NOT).

public class MyClass


{
public static void main(String[] args)
{
int x = 5;
[Link](!(x > 3 && x < 10));
// returns false because ! (not) is used to reverse the result
}
}
Chapter-4 STORING & OPERATING ON DATA
Output:
False

[Link] a program in java using Increment operator.


class Increment
{
public static void main(String[] args)
{
double number = 5.2;

[Link](number++);
[Link](number);

[Link](++number);
[Link](number);
}
}
Output:
5.2
6.2
7.2
7.2

[Link] a program in java using Decrement operator.


class Decrement
{
public static void main(String[] args)
{
double number = 5.2;

[Link](number--);
[Link](number);

[Link](--number);
Chapter-4 STORING & OPERATING ON DATA
[Link](number);
}
}

[Link] a program in java to find the sum of two numbers using import the scanner
class to capture user input.

import [Link];
public class Add
{
public static void main(String[] args)
{
int a, b, sum;
Scanner sc = new Scanner([Link]);

[Link]("Enter First Number: ");


a = [Link]();

[Link]("Enter Second Number: ");


b = [Link]();

sum = a + b;
[Link]("Sum of these numbers: "+sum);
}
}
Chapter-4 STORING & OPERATING ON DATA
[Link] a program in java to find the difference between two numbers using import the
scanner class to capture user input.

import [Link];
public class Difference
{
public static void main(String[] args)
{
int a,b,sub;
Scanner sc=new Scanner([Link]);

[Link]( "Enter the first number");


a=[Link]();

[Link]( "Enter the second number");


b=[Link]();

sub=a-b;
[Link]("The difference between two number is: " +sub);

}
}

You might also like