473,395 Members | 1,468 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

programing to get the maximum and minimum numbers

hello can any one please help me i have a test and i need to study the java scripts, i know that i have to use arrays but im still a bit confuse the question is to ask the user how many data items he/she has using N, then i have to ask the user to input the N Data times (we assume that all the data are integers from -100 to 100 inclusive) then it has to output the maximum and the minimum value of the users data, please can any one help me or give me some hints. thank you
Apr 14 '07 #1
18 20415
hello can any one please help me i have a test and i need to study the java scripts, i know that i have to use arrays but im still a bit confuse the question is to ask the user how many data items he/she has using N, then i have to ask the user to input the N Data times (we assume that all the data are integers from -100 to 100 inclusive) then it has to output the maximum and the minimum value of the users data, please can any one help me or give me some hints. thank you
Hi,
I don't know abt' java script but I can help you telling the logic of the program( as far as I know ).

1 --> prompt the user to enter the number of integers he wants to enter.
2--> read that number and store it in a variable( say N ).
3--> take two integer variables min and max.
int min ;
int max;
4--> prompt the user to enter the first value save it in a variable( say value )
min = value;
max = value;
5--> use a for loop to prompt the user N-times to enter N numbers.
for( int counter = 2; counter < N; counter++ )
{
a) prompt the user to enter the value
b) read the value and save it in value
c) if( value <= N && value >= -N )
{
if( min > value )
min = value;
if( max < value )
max = value;
}
}

6--> Now, you output the maximum number which is stored in max and
minimum number which is stored in min.

Hope this helps.
All The Best for the test.
Apr 14 '07 #2
Hi,
I don't know abt' java script but I can help you telling the logic of the program( as far as I know ).

1 --> prompt the user to enter the number of integers he wants to enter.
2--> read that number and store it in a variable( say N ).
3--> take two integer variables min and max.
int min ;
int max;
4--> prompt the user to enter the first value save it in a variable( say value )
min = value;
max = value;
5--> use a for loop to prompt the user N-times to enter N numbers.
for( int counter = 2; counter < N; counter++ )
{
a) prompt the user to enter the value
b) read the value and save it in value
c) if( value <= N && value >= -N )
{
if( min > value )
min = value;
if( max < value )
max = value;
}
}

6--> Now, you output the maximum number which is stored in max and
minimum number which is stored in min.

Hope this helps.
All The Best for the test.




thank you so much,
Apr 14 '07 #3
Hi,
I don't know abt' java script but I can help you telling the logic of the program( as far as I know ).

1 --> prompt the user to enter the number of integers he wants to enter.
2--> read that number and store it in a variable( say N ).
3--> take two integer variables min and max.
int min ;
int max;
4--> prompt the user to enter the first value save it in a variable( say value )
min = value;
max = value;
5--> use a for loop to prompt the user N-times to enter N numbers.
for( int counter = 2; counter < N; counter++ )
{
a) prompt the user to enter the value
b) read the value and save it in value
c) if( value <= N && value >= -N )
{
if( min > value )
min = value;
if( max < value )
max = value;
}
}

6--> Now, you output the maximum number which is stored in max and
minimum number which is stored in min.

Hope this helps.
All The Best for the test.




thank you so much, oh ok i have a question, i know i have to INput N ans input users N data values but what does that mean, do i seet it pu like this
largest value N=2;
smallest vaule N= 100;
for (int N = 2; N< 100; N++)
Apr 14 '07 #4
Hi,
I don't know abt' java script but I can help you telling the logic of the program( as far as I know ).

1 --> prompt the user to enter the number of integers he wants to enter.
2--> read that number and store it in a variable( say N ).
3--> take two integer variables min and max.
int min ;
int max;
4--> prompt the user to enter the first value save it in a variable( say value )
min = value;
max = value;
5--> use a for loop to prompt the user N-times to enter N numbers.
for( int counter = 2; counter < N; counter++ )
{
a) prompt the user to enter the value
b) read the value and save it in value
c) if( value <= N && value >= -N )
{
if( min > value )
min = value;
if( max < value )
max = value;
}
}

6--> Now, you output the maximum number which is stored in max and
minimum number which is stored in min.

Hope this helps.
All The Best for the test.




thank you so much, oh ok i have a question, i know i have to INput N and input users N data values, do i seet it up like this
largest value N=2;
smallest vaule N= 100;
for (int N = 2; N< 100; N++)
Apr 14 '07 #5
{
public static void main(String args{})
{
largerst value n= 2;

smallest value m= 100
for (int n= 2; n < m; n++)

System.out.println(n);

{

if (smallest value n= 2)

System.out.println(m);

if (largest value m= 100)

System.out.println (m= 100)

}
}

ok ive been working with some help for my test but my program is not running correctly can anyone please check it,

this is a sample run of the program
How many data items do you have? 5 <--- users inputs 5
Input next data item: 10 <---user inputs 10
Input next data item: 50 <---user inputs 50
Input next data item: -8 <---user inputs -8
Input next data item: 100 <---user inputs 100
Input next data item: 10 <---user inputs 10
the maximum value is : 100
the minimum value is : 8
please can any one help me, thank you so much...
Apr 14 '07 #6
thank you so much, oh ok i have a question, i know i have to INput N and input users N data values, do i seet it up like this
largest value N=2;
smallest vaule N= 100;
for (int N = 2; N< 100; N++)
Hi,
I don't know whether I understood your question correctly, but if you mean that you have to allow user to enter 100 values in between -100 and 100, then you simply need to omit step 1 and step 2. You can say,

Step1 --> int N = 100;
Step 2--> take two integer variables min and max.
int min ;
int max;
Step 3--> prompt the user to enter the first value save it in a variable( say value )
min = value;
max = value;
( After step 3 you need to prompt only 99 times to the user to enter the value, that's why you start your counter( in the for loop) from 2 till it reaches 100. You no need to change min( i.e larger value) or max( i.e smaller value) )

Step 4--> for( int counter = 2; counter < N; counter++ )
{
a) prompt the user to enter the value
b) read the value and save it in value
c) if( value <= N && value >= -N )
{
if( min > value )
min = value;
if( max < value )
max = value;
}
}

Step 5--> Now, you output the maximum number which is stored in max and
minimum number which is stored in min.

I'll send you the test case so that it'll help you in getting the logic properly.
Apr 14 '07 #7
thank you,
this is what i have



{
public static void main(String args{})
{
largerst value n= 2;

smallest value m= 100
for (int n= 2; n < m; n++)

System.out.println(n);

{

if (smallest value n= 2)

System.out.println(m);

if (largest value m= 100)

System.out.println (m= 100)

}
}

can you please check the commands

this is a sample run of the program
How many data items do you have? 5 <--- users inputs 5
Input next data item: 10 <---user inputs 10
Input next data item: 50 <---user inputs 50
Input next data item: -8 <---user inputs -8
Input next data item: 100 <---user inputs 100
Input next data item: 10 <---user inputs 10
the maximum value is : 100
the minimum value is : 8
Apr 14 '07 #8
r035198x
13,262 8TB
1.)Please do not double post. (Threads merged)

2.)When posting code, let's all remeber to do so using code tags.
Apr 14 '07 #9
[quote=r035198x]1.)Please do not double post. (Threads merged)

2.)When posting code, let's all remeber to do so using code tags.[/QUO

im really sorry
Apr 14 '07 #10
TEST CASE : -

Step 1 --> Lets take N = 3( you can analyze abt' 100 by yourself )

Step 2 --> int min;
int max;


Step 3--> Prompt user -- Please enter the first value
suppose user enters - 2
Therefore, value = 2
min = 2
max = 2

Note :- You took the first value. Now, you have to prompt only 2 times more to the user to enter the values. So, counter starts from 2 in the for loop.

Step 4--> for( counter = 2; counter(i.e, 2 ) <= N( i.e, 3 ); counter++ )
{
Prompt user -- Please enter the value
suppose user enters - 0
Therefore, value = 0
if( value( 0 )<= N( 3 ) && value( 0 ) >= -N( -3 ) )// condition satisfies
{
Step 4.1--> if( min( i.e, 2 in step 3) > value( 0 ) )// condition is true
min = value => min = 0
Step 4.2--> if( max( i.e, 2 in step 3) < value( 0 ) )// condition is false
max = value => max = 2// doesn't change
}

}
Now, counter becomes counter+1 = 3
for( counter = 3; counter(i.e, 3) <= N(i.e, 3),counter++ )
{
Prompt user -- Please enter the value
suppose user enters - 3
Therefore, value = 3
if( value( 3 )<= N( 3 ) && value( 3 ) >= -N( -3 ) )// condition satisfies
{
if( min( i.e, 0 in step 4.1) > value( 3 ) )// condition is false
min = value => min = 0// doesn't change
if( max( i.e, 2 in step 4.1) < value( 3 ) )// condition is true
max = value => max = 3
}

}
Now, counter becomes counter+1 = 4
but 4 > 3 and hence in the for loop stops.
Step 5 --> return the values that are stored finally in min and max i.e
min = 0 and max = 3
Apr 14 '07 #11
TEST CASE : -

Step 1 --> Lets take N = 3( you can analyze abt' 100 by yourself )

Step 2 --> int min;
int max;


Step 3--> Prompt user -- Please enter the first value
suppose user enters - 2
Therefore, value = 2
min = 2
max = 2

Note :- You took the first value. Now, you have to prompt only 2 times more to the user to enter the values. So, counter starts from 2 in the for loop.

Step 4--> for( counter = 2; counter(i.e, 2 ) <= N( i.e, 3 ); counter++ )
{
Prompt user -- Please enter the value
suppose user enters - 0
Therefore, value = 0
if( value( 0 )<= N( 3 ) && value( 0 ) >= -N( -3 ) )// condition satisfies
{
Step 4.1--> if( min( i.e, 2 in step 3) > value( 0 ) )// condition is true
min = value => min = 0
Step 4.2--> if( max( i.e, 2 in step 3) < value( 0 ) )// condition is false
max = value => max = 2// doesn't change
}

}
Now, counter becomes counter+1 = 3
for( counter = 3; counter(i.e, 3) <= N(i.e, 3),counter++ )
{
Prompt user -- Please enter the value
suppose user enters - 3
Therefore, value = 3
if( value( 3 )<= N( 3 ) && value( 3 ) >= -N( -3 ) )// condition satisfies
{
if( min( i.e, 0 in step 4.1) > value( 3 ) )// condition is false
min = value => min = 0// doesn't change
if( max( i.e, 2 in step 4.1) < value( 3 ) )// condition is true
max = value => max = 3
}

}
Now, counter becomes counter+1 = 4
but 4 > 3 and hence in the for loop stops.
Step 5 --> return the values that are stored finally in min and max i.e
min = 0 and max = 3
thank you, you really help me a lot, hopefully ill do good on the test
Apr 14 '07 #12
thank you,
this is what i have



{
public static void main(String args{})
{
largerst value n= 2;

smallest value m= 100
for (int n= 2; n < m; n++)

System.out.println(n);

{

if (smallest value n= 2)

System.out.println(m);

if (largest value m= 100)

System.out.println (m= 100)

}
}

can you please check the commands

this is a sample run of the program
How many data items do you have? 5 <--- users inputs 5
Input next data item: 10 <---user inputs 10
Input next data item: 50 <---user inputs 50
Input next data item: -8 <---user inputs -8
Input next data item: 100 <---user inputs 100
Input next data item: 10 <---user inputs 10
the maximum value is : 100
the minimum value is : 8
I posted the test data. I think it will help you.
You said that you are using java script but I think you wrote the program in Java. Do you know how to use Sacanner class? If so, then I can help you out in doing the code. When is your test? Let me know.

Ok then, bye.
Apr 14 '07 #13
thank you, you really help me a lot, hopefully ill do good on the test
You are welcome. Hope you do your best in the test. All the very best.

KiranJyothi
Apr 14 '07 #14
You are welcome. Hope you do your best in the test. All the very best.

KiranJyothi
hello, my test is on friday, but it take a while for me to get java, i preffer math, the tips did help me but i think you a little advance than me, no we have not talked about "scanner" we are dealing with ARRays, and loops, while loops, for loops, the basic thing, i appreciate the help, the test consists of writting java programs.
Apr 14 '07 #15
hello, my test is on friday, but it take a while for me to get java, i preffer math, the tips did help me but i think you a little advance than me, no we have not talked about "scanner" we are dealing with ARRays, and loops, while loops, for loops, the basic thing, i appreciate the help, the test consists of writting java programs.
Ok then, see you later.
Bye.
Apr 14 '07 #16
r035198x
13,262 8TB
hello, my test is on friday, but it take a while for me to get java, i preffer math, the tips did help me but i think you a little advance than me, no we have not talked about "scanner" we are dealing with ARRays, and loops, while loops, for loops, the basic thing, i appreciate the help, the test consists of writting java programs.
There are many approaches to revision.
Don't try to learn everything at once. It's better to get into the exam knowing 100% of 70% of the content (syllabus) rather than going there knowing 50% of 100% (half of everything) of the content.
Apr 14 '07 #17
Ok then, see you later.
Bye.
yes so if i need you help again can i ask you
Apr 14 '07 #18
yes so if i need you help again can i ask you
Of Course. I check this forum continuously.
On Monday and Tuesday I may not reply because I have two tests on tuesday.
But, I'll try to reply your questions as soon as I can.

Ok then, bye.
Apr 14 '07 #19

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Lobang Trader | last post by:
Hi all, I am trying to create a username and a password class. I would like to know what are the RECOMMENDED minimum and maximum length for both fields? These fields will be something like...
5
by: Chris Brew | last post by:
I've just been writing some code to merge items from a collection of streams, where each item has a key, and each stream is known to be sorted in ascending order of key. I read all the streams...
1
by: Stefan Franke | last post by:
Hi, I'm trying to figure out if it's possible to find out a minimum or a maximum via XPath 1.0. The XML document I'm working on looks like this: <doc> <val>10</val> <val>5</val>...
2
by: Hennie de Nooijer | last post by:
I have a problem (who not?) with a function which i'm using in a view. This function is a function which calculates a integer value of a date. For example: '12/31/2004 00:00:00" becomes 20041231....
2
by: Hennie de Nooijer | last post by:
Because of an error in google or underlying site i can reply on my own issue. Therefore i copied the former entered message in this message....
1
by: itsolutionsfree | last post by:
Hi All, i am deep trouble.so,please help me how to get minimum and maximum dates for particular Month and Year.Any kind of help will help. for ex: im passing : March 2006 Minimum Date -...
2
by: Pugi! | last post by:
hi, I am using this code for checking wether a value (form input) is an integer and wether it is smaller than a given maximum and greater then a given minimum value: function...
3
by: Frank Rizzo | last post by:
I am trying to do some monitoring of some PerfMon counters and have a question. Does PerfMon figure out the Minimum, Maximum, Average values for each counter? Or are those values part of the...
11
by: zj262144 | last post by:
Hi, I'm a C beginner. I want to write a C. The pseudocodes are like this: User enters some numbers (use -1 to end) The compiler find and delete the maximum and minimum numbers Then average...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.