Even number routine
I have to test if a value is even. The value can be from 0 - 560. What is the simpliest (and most efficient) way of writing this routine
thanks
REPORT Z_N_EVEN_NO.
DATA: V_NO TYPE I,
RESULT TYPE I.
PARAMETERS: P_NO TYPE I.
IF RESULT = P_NO MOD 2.
RESULT = 0.
WRITE:/ ' THE NO IS EVEN NO'.
ELSE.
WRITE:/ ' THE NO IS AN ODD NO'.
ENDIF.
Similar Messages
-
How to find the largest odd number and smallest even number from an array
Hello All
I want to find out largest odd number and the smallest even number from an arry numbers? What is the best method to achieve this.
Thanks
SravzYou need to sit down and figure out an algo on how you would do it if you had to do the same thing from a blind container perspective:
1 - collect all the items you want to look at
2 - look at an item
3 - is it odd?
4 - if it is odd then check if it is larger than previously largest number
5 - save it if it is larger
6 - return back to 2 unless no more items
7 - item is not odd so it must be even--is it smaller than previous
8 - save it if it is smaller
9 - return back to 2 unless no more items
Now you just need to know how to check if something is even or odd: to do this you will need the modulous operator--integer division.
Note: this all assumes that your needs are for integer type of numbers, otherwise there is not enough information to define an answer. For instance, if you are using floats at 0.5--it that even or odd? Do you consider an err factor when dealing with floats? etc... -
FINDING MEDIAN FOR AN ARRAY OF INTS WITH EVEN NUMBER OF VALUES
okie dokie fellas i know this has got to be easy but i hjave been sittin at my comp forever workin on projects that are due and my head isn't all there anymore...could someone please clue me in on how im supposed to write the logic to find the median of an array of integers if the array contains an even number of values...I know I have to average the 2 values on either side but i cant figure it out at all...sorry i know its dumb but thnaks to anyone who helps
package pgm3deClercqMatt;
* @author Owner
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
import java.sql.*;
import javax.swing.*;
import java.awt.*;
import java.util.*;
import java.text.*;
public class ExamStatistics
public static void main(String[] args)
DbConnection db = new DbConnection("pgm3");
boolean moreRecords;
String query = "SELECT * FROM pgm3Data ORDER BY ExamGrade";
ResultSet rs = db.processQuery(query);
int nbrGrades = 0;
ResultSetMetaData rsmd = null;
try
rsmd = rs.getMetaData();
catch(SQLException sqlex)
JOptionPane.showMessageDialog(null, "SQLException getting ResultSet data or metadata");
System.exit(0);
int s[] = new int[200];
DecimalFormat decimal = new DecimalFormat("#,##0.00");
int n = 0, aboveNinety = 0, numberAboveNinety = 0;
double sum = 0, avgGrade = 0, medianGrade = 0;
try
moreRecords = rs.next();
if(!moreRecords)
JOptionPane.showMessageDialog(null, "pgm3Data Result Set is Empty.");
System.exit(0);
while(moreRecords)
s[n] = rs.getInt(1);
n++;
moreRecords = rs.next();
}// end of while loop
System.out.println("n = " + n);
System.out.println("s[0]= " + s[0]);
System.out.println("s[n-1]= " + s[n-1]);
//FIND AVERAGE OF ARRAY
for(int j=0; j<n; ++j)
sum += s[j];
avgGrade = sum/n;
//FIND NUMBER OF GRADES ABOVE OR EQUAL TO 90
for(int j=0; j<n; ++j)
if(s[j]>=90)
numberAboveNinety++;
//FIND MEDIAN EXAM GRADE
for(int j=0; j<n ; ++j)
if(Math.abs(medianGrade - Math.floor(medianGrade))<1.e-10)
medianGrade = s[(j+1)/2];
else
medianGrade = <HERE IS WHERE THE PROB IS
}// end of try block
catch(SQLException sqlex)
JOptionPane.showMessageDialog(null, " SQLException getting ResultSet data or metadata");
System.exit(0);
String output = "";
output = "Number of Exam Grades: " + n;
output += "\nHighest Exam Grade: " + maxOfArray(s, n) + "\nLowest Exam Grade: " + minOfArray(s, n)
+ "\nAverage Grade: " + decimal.format(avgGrade) + "\nNumber of exam grades above 90: "
+ numberAboveNinety + "\nMedian Exam Grade: " + medianGrade;
JOptionPane.showMessageDialog(null, output);
System.exit(0);
}// end of main
static int maxOfArray(int z[], int n)
int j, max = z[0];
for(j=1; j<n; ++j)
if(z[j]>max)
max = z[j];
return max;
static int minOfArray(int z[], int n)
int j, min = z[0];
for(j=1; j<n; ++j)
if(z[j]<min)
min = z[j];
return min;
}// end of ExamStatistics
class DbConnection
// class DbConnection creates and manages the db connection,
// processes queries, and returns result sets for processing
private Connection connection = null;
private String url="jdbc:odbc:";
private Statement statement;
private String username = "";
private String password = "";
private ResultSet rs;
private int nbrResultSets = 0;
// Constructor Argument is the registered name of the database
DbConnection(String dbName)
try
{// load driver to allow connection to database
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
connection = DriverManager.getConnection ((url+dbName), username, password );
catch (ClassNotFoundException cnfex)
fatalError("ClassNotFoundException on connection attempt");
System.exit(0);
catch (SQLException sqlex )
fatalError("SQLException -- Unable to Connect to db");
System.exit(0);
} // end of constructor
ResultSet processQuery(String query)
// process a single SQL query and return the resulting data set
rs = null;
try
statement = connection.createStatement();
rs = statement.executeQuery(query);
catch (SQLException sqlex)
fatalError("SQLException on query or processing");
return rs;
void endConnection()
try
connection.close();
catch (SQLException e)
fatalError("SQLException on attempt to close connection");
// simple local fatal error handler
private void fatalError(String msg)
JOptionPane.showMessageDialog(null,msg);
System.exit(0);
} // end of class DbConnectionsorry to anyone who thinks what i'm doing is a joke
first of all i'm a student and secondly i'm taking
java in a summer session so things don't get
explained as well as they should. And how is this our problem?
I'm doing the best
i can. The for loop was because the array that I
defined to hold 200 values was being filled by a
database with a supposed unknown number of values but
less than 200 so i waslooping through to get each
value and put it in order and the conditional
statement was supposed to test to see if the incoming
median was an integer and was in the final write-up
put into it's own boolean method returning false if
there was no median and you needed to take the
average of the next lowest and highest values. BThere's always a median. The definition I sent you tells you what it is.
But
thnak you very much to the people that actually help
on here and don't try to bash people who have put
effort into writing their code, however shitty it may
look to them. You can't control what people say about your stuff. Everyone who criticizes your work isn't making a personal attack. They're telling you something that you should be learning from. Your problem is that you can't separate yourself from your work.
No one knows absolutely everything and
people who decide to talk down on others when they
are using this forum as a last resort need to grow
up.Grow up? That's what you need to do. If you think for a moment that you'll never be criticized once you leave that ivory tower you're sadly mistaken. You need to figure out how to separate yourself from your code.
% -
"generate subset" in script gives error if even number
I am try to generate with a scipt using a PXI6551. In the generate subset command if it is a EVEN number such as below (gree) subset(0,17) it gives the error below (red). If it is an ODD number it works. Is this a bug, normally you would need an even number of samples to be able to generate but with the script it seems to give the error if there is an even number?
Thanks,
Brian
script myScript
repeat 1
Generate PRBS
end repeat
Generate PRBS subset(0,17) <-gives error (0,18) does not give error
script
Error -1074115617 occurred at niHSDIO Write Script.vi
Possible reason(s):
Driver Status: (Hex 0xBFFA4BDF) DAQmx Error -200032 occurred:
Subset length specified is not valid.
Change the subset length to be longer than zero samples and a multiple of the alignment quantum.
Line Number: 5
Position in Line: 18
Subset Length: 17
Alignment Quantum: 2
Status Code: -200032
Message Edited by BrianPack on 09-29-2005 04:29 PMBrian,
The format (x,y) means y samples starting at position X and therefore when you specify (0,17) you would still generate 17 samples but starting at position 0. Whereas when specifying (1,17) you would generate STILL 17 samples but starting at position 1. Therefore, in either case, you are still asking to generate an odd number of samples. Hope this helps.
Ayman K -
Write a program that is supposed to read 500 integers from user. Use a break statement to stop the reading if any negative even number is entered. Display that number
Can anyone write the pseudocode for this question?
The thing that bothers me is that a negative even number, How do I write the code to stop this one?
Can anyone also write the computation part? I'd do the remaining whole body. Thank you ( Just a rough figure will help a lot ) Thanksxcoder wrote:
Write a program that is supposed to read 500 integers from user. Use a break statement to stop the reading if any negative even number is entered. Display that number
Can anyone write the pseudocode for this question?
The thing that bothers me is that a negative even number, How do I write the code to stop this one?
Can anyone also write the computation part? I'd do the remaining whole body. Thank you ( Just a rough figure will help a lot ) Thanks
pseudo code:
read 500 integers
if less than 0 and even
display number
stopto check if negative:
if(myNumber<0){do something here}to check if even:
myTest = myInt/2;
if(myInt == (myTest*2)){do something here}BTW: there are other ways of doing this, but you should have been able to at least think of this one. -
Create function for ODD or EVEN(NUMBER) in pls sql
create function for ODD or EVEN(NUMBER) also
if number is odd multiply by 5
if number is even multiply by 10;865253 wrote:
create function for ODD or EVEN(NUMBER) also
if number is odd multiply by 5
if number is even multiply by 10;
create function fn_get_no (n_in in number) return number is
o_num number;
begin
if mod(n_in,2) = 0 then
o_num := n_in*10;
else
o_num := n_in*5;
end if;
return o_num;
end;
select fn_get_no(5) odd, fn_get_no(4) even from dual;
ODD EVEN
25 40 Vivek L -
Regex: check string for even number of a symbol
Hi,
for example "ass'asd'asd" is valid, but "asd'asd'asd'asd" is not, for symbol " ' ". I have tried every combination of \w, [...],',+ and nothing...
Ideas?what is doing the %2 here, prome' ?If there are an even number of char symbol in String s, then s.length() - s.replace(""+symbol, "").length() will also be even. So that number mod 2 will equal zero (and return true).
-
Hi All,
MAXDOP Setting with an EVEN number will outperform ODD number. If any of you have any data points, please share.
NASTY RUMORS ABOUT MAXDOPI do not think there is any relations between specifying even and odd numbers in MAXDOP... What are you trying to achieve?
http://sqlblog.com/blogs/adam_machanic/archive/2010/05/28/sql-university-parallelism-week-part-3-settings-and-options.aspx
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
Odd even number and Boolean indicator
Hi all,
For example, I have these numbers from 0 to 112233. It will start counting from 0 and shown it on an output indicator. When it is even number (0,2 or 4,...) the Boolean indicator will become false, but when it is odd number (1,3 or,...) the Boolean indicator will become true.
I'd like to ask if it is possible to detect the values changing in output indicator when it start counting numbers from 0, and then the Boolean indicator will become false or true depending on even or odd number shown on an output indicator? How can I do that?
Thank you!johnsold wrote:
It may not be that much faster. In the little test VI Q&R takes 581 ms for 10^8 iterations while AND takes 503 ms. That is 78 ps difference. Hardly enough time for a coffee break. Unless you drink really fast.
Yes, both are "fast enough" for all practical purpose. Even thought they are nealy identical in speed, the Q&R shows more variability in execution time (10% variability), while the AND is singificantly more stable (>1% variability).
(Make sure you disable debugging for a 10x speedup overall)
It also seems that the AND code folds better. If we change the control to a diagram constant, the AND version speeds up by a factor of two, even though no folding is shown anywhere inside the sequence structure. I have no idea what that means.
LabVIEW Champion . Do more with less code and in less time . -
Is varchar2(9) or even number(9) bad as a ssn?
Hi All,
I just want to question the wisdom of (<INT>) datatypes.
If I do ...
create table table_0123 (
ssn varchar2(9),
... in tons of tons code (or even in a small piece of code
that gets used or modified over and over), won't I be setting
my self up for a Y2K like problem if there is ever more than
999,999,999 people with SSN's? What is that ... 1 billion people?
How many people are in the world?
wouldn't ...
create table table_0123 (
ssn number,
be better?
ThanksSo you're compiling a database that holds details of everybody in the whole world? Spooky. Still you've come to the right place: Oracle started out as a CIA project.
Datatype for SSN: hmmm. I'm not American, so I'm not familiar with your system. On this side of the pond our SSN equivalents (NIN) are of the format AA999999A, which gives us 17,575,982,424 combinations (or thereabouts, I don't know if there are any excluded characters). This is sufficient for a few centuries of UK existence, but not very good for the whole world. But, given an alphanumeric format, VARCHAR2(9) is the only viable definition.
If you have a purely numeric SSN then NUMBER is a goer. Please do not choose VARCHAR2(9) for a purely numeric field - I have a (third party) legacy system here that has that combination for the primary key of the most referenced table, which means having to LPAD everything with zeroes. Nightmare.The choic
As the following test shows, all NUMBER fields take up the same about of space so there are no storage implications for you. The choice is merely a question of the amount of metadata you wish to build into your system.
When you acheive world domination can I be your cackling, hunchbacked sidekick?
Cheers, APC
SQL> create table num_tst (col1 number(9,0), col2 number(38,0), col3 number);
Table created.
SQL> select column_name, data_length, data_precision, data_scale
2 from user_tab_columns
3 where table_name = 'NUM_TST';
COLUMN_NAME DATA_LENGTH DATA_PRECISION DATA_SCALE
COL1 22 9 0
COL2 22 38 0
COL3 22
SQL> -
Odd or even number comparison?
Anyone know how to compare an incoming number and tell whether it is odd or even? How about if it is whole or fractional? Thanks
Kirkfabb wrote:
Anyone know how to compare an incoming number and tell whether it is odd or even? How about if it is whole or fractional? Thanks
You need to be very careful applying odd/even to floating point numbers. It is only defined for intergers. Especially, if the value is a result of some computations, it could actually be 2.000000001 instead of 2.
Same with whole vs. fractional. You probably need additional code to ignore small differences from whole numbers. Where does the data come from?
ODD/EVEN: If you have an integer datatype, do a bitwise AND with "1" and check if the result is zero (even) or not (odd).
Message Edited by altenbach on 05-27-2008 09:17 AM
LabVIEW Champion . Do more with less code and in less time .
Attachments:
OddEven.png 3 KB -
ok , basically how can I write a line of code which will tell me if a number is odd or even?
the test for equality with 0 should work for all numbers - the remainder of dividing a negative number by two should be 0 or -1 (I think - and the code bears this out anyway)
Lee -
how can i get a script to tell me if the file count of a particular folder is an even or an odd number?
pedroset _count to 1002401
if _count mod 2 is 0 then
return "Even Steven"
else
return "Odd Todd"
end if -
When installing memory do you have to have an even number of cards to run parallel?
I bought a 4GB card so that would be two stock and the one I bought. 3 total. Where can I find the 'carrier' thing the actuall card slips into?
Do I have to have 4 or can I run 3? thanks for any help.Hi there. thanks for the response. I have a 2008 and previous. below is my info. So I guess I would have to buy another card to make four? I don't remember getting any extra riser cards. I only have the two that are in there now. I have the two memory trays. the top is upside down (pic attached). I bought the memory from macmall and spoke with a rep to make sure it would work. Looks like it should but haven't tried yet.
Thanks again.
Model Name: Mac Pro
Model Identifier: MacPro1,1
Processor Name: Dual-Core Intel Xeon
Processor Speed: 2.66 GHz
Number Of Processors: 2
Total Number Of Cores: 4
L2 Cache (per processor): 4 MB
Memory: 1 GB
Bus Speed: 1.33 GHz
Boot ROM Version: MP11.005C.B08
SMC Version (system): 1.7f10
Serial Number (system): YMXXXXXXXQ2
Hardware UUID: 00000000-0000-1000-8000-0017F2050F8E
<Message was edited by Host> -
Function detect odd and even number
Do you know a function which can detect if a number is an odd number or other.
if ( number%2 == 1)
But a method for this? Really doubt that..
Do you know a function which can detect if a number is
an odd number or other.
Maybe you are looking for
-
Custom Styled Top Link Bar Sharepoint Foundation 2013
I want to be able to style the top link bar with some custom CSS but I am unable to find any guides that walk me through the process. I could use a step by step guide. I have sharepoint designer and I know how to open the master page for editing. I'v
-
SMS and/or email notifications from iPhone/iPod Touch calendar(s)
My wife and I have iPod Touch's that we use to sync 2 calendars. Is there ANY way to get SMS or email notifications of an event? By syncing google calendar it will work ONLY if the event is created via google calendar - it won't work if it's created
-
ITunes cant handle VBR LAME mp3s (not anecdotal case, how do I contact tech
I use iTunes primarily on Windows XP. Starting with 6.0.2, playback of MP3's encoded with LAME using VBR settings resulted in problems - namely songs cutting off too early. iTunes has always handled the timing of these mp3's wrong (showcased when the
-
Goods Return or AP Credit Memo Creation if AP Reserve Inv created
Hi All, Can anyone tell me how to create good return or ap credit note if ap reserve invoice is used. GRPO created with reference to ap reserve invoice always closed. Regards
-
can some one help me in Rewriting a query which i am just confused with the syntax SELECT DISTINCT sypro.code , sypro.usage, sypro.user_create, sypro.user_modif, aprol.description, sypro.VALUE,