Search: | |||||

| ||||

Home » Forum » Java | RSS Feeds |

i ve just started learning. my question is really of

novie level . you can say i am "hello world" category programmer.

Recently i ve started learning java in my university.

my teacher gave me a assigment in which he said that programm should

judge wether the given number in variable is Even or ODD .The

program should be coded by 4 methods.i ve coded by 2 methods using %

reminder operator and other method is float integer camparsion

method.

the further 2 methods that my teacher and i want is tat

check integer number without using any % and / operators .with only

bitwise operators allowed.

and

3rd last is

check the number by using the conditional operators.

can any one of you help me in this as i am fairly new to programming

and cant find the logic of doing it all ; example codes will be

prefered.

int x =11

while(x >0){

x-=2;

}

System.out.println(x==0 ? "Even":"Odd");

Keep in mind that any odd number can be broken up into an even

number+1. Also remember how numbers are stored in binary (a sum of

different powers of 2). Since an odd number always has the number 1 in

its sum, you can check the bit for that value by doing a bitwise and.

If the bit is set, then the number's odd.

Conditional:

Do you mean the ternary operator? --> (cond) ? doIfTrue: doIfFalse

The only way I see of using this is (cond)?true:false;, where cond is

any check for an odd number.

Didn't find what you were looking for?
Find more on Beginers Problem
Or get search suggestion and latest updates.

Related Topics:

- Problem with Workbooks.opentext problem
- webform button problem
- Is there a problem with this code?
- pop up window problem
- problem in ASP not ASP.net
- Server problem
- Problem with editable datagrid...
- repeater update data problem
- Problem with delete confirmation in datagrid
- Rendering Problems
- Session problem
- Repeater problems
- problem with conditional output in templates
- Problem with Cookies and Keys
- .Net Email Problem
- SMTP mail problem
- Src Problem for User Controls in SubDirectories
- problem with page_loading
- problem with page_loading
- Shorter Version of Validator Problem
- problem with session interacting between 2 webforms..
- Microsoft Visual Studio creating Problems
- Crystal Reports Problem
- Problem with Validators
- Problem With Strings