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
- Help Needed on This Excel Problem
- web browser control problem
- PROBLEM IN CLOSING WORKBOOKS IN VB.NET
- excel 2000 - Wierd Paste Problem
- Fix for Problem with CommandButton font property?
- Problem after 9 counts
- Problem using VB6 (not VBA) to put picture file into Excel
- VBA Help With Chart Object Problem
- Wierd problem in VBA code re Mid function
- Problems in writing VBA code for an ActiveX control
- Problem with simple error trap
- Problem copying/pasting with variable in worksheet name
- overflow problem
- Problem with named ranges
- Handmade Map and Transparent Problem
- AddIn Problem
- Problem with VLookup in VBA
- Problem with calling Sub from UserForm
- problem with colorpicker
- Problem with user for in Excel
- Another problem with coding
- Form problem
- Problem with Excel Automation from Access
- Delete Sheet Problem, Excel Crash !