0% found this document useful (0 votes)
36 views2 pages

Data Structures and Algorithms: Assignment #1

The document provides two algorithms written in Java: 1) An algorithm to determine if a number is even or odd by taking user input, dividing the number by 2, and checking if there is a remainder. 2) An algorithm to swap the values of two variables, A and B, initially set to 30 and 60 respectively, by storing the value of A temporarily in a third variable C, assigning A to B, and then assigning C to B.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views2 pages

Data Structures and Algorithms: Assignment #1

The document provides two algorithms written in Java: 1) An algorithm to determine if a number is even or odd by taking user input, dividing the number by 2, and checking if there is a remainder. 2) An algorithm to swap the values of two variables, A and B, initially set to 30 and 60 respectively, by storing the value of A temporarily in a third variable C, assigning A to B, and then assigning C to B.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

DATA STRUCTURES AND ALGORITHMS

Submitted by: Ms. Geraldine Absalon Dadural

Submitted to: Mr. Joe Anthony M. Milan

ASSIGNMENT #1
Writing an algorithm in Java Programming

1. Write an algorithm to find whether a number is an even or


odd.

1. Start your program.


2. Generate and create an object of the scanner class to take input from the user.
3. Declare the variable to store the number.
4. Ask your user to initialize the number.
5. Review your program, analyze and test of it whether your number is divisible by 2
or not to be entered by your users.
6. Enter any number. If your number is divisible by 2, then, your number that you
have entered is even number.
7. Enter again any number. If your number is not divisble by 2, then your number
that you have entered is odd number.
8. It will display your result.
9. Stop the program.

2. Write an algorithm to swap to values A=30 and B=60.

1. Set up and Start your program.


2. Declare three (3) variables to store those integers.
3. Input those two numbers, 30 and 60.
4. In program, it is already gets stored as A=30 and B=60, and we
will be having a declaration in a variable c, because, if we put A=B,
then the value of B will gets stored in A, by then, the value will be
removed.
5. Settle the value of A in C, it looks like this, c=a ; so, C
becomes 30 then we put A=B, so, now A it will becomes 60.
6. Put the value of C that will stored the value of A in B, ; b=a ;
our b becomes 30.
7. Print those values.
8. Displaying of results.
9. Stop the program.

You might also like