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
programing to get the maximum and minimum numbers
Collapse
X
-
Hi,Originally posted by Rose4msmhello 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
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. -
Originally posted by KiranJyothiHi,
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,Comment
-
Originally posted by KiranJyothiHi,
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++)Comment
-
Originally posted by KiranJyothiHi,
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++)Comment
-
one more question on programing to get the maximum and minimum as the input using Jav
{
public static void main(String args{})
{
largerst value n= 2;
smallest value m= 100
for (int n= 2; n < m; n++)
System.out.prin tln(n);
{
if (smallest value n= 2)
System.out.prin tln(m);
if (largest value m= 100)
System.out.prin tln (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...Comment
-
Hi,Originally posted by Rose4msmthank 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++)
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.Comment
-
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.prin tln(n);
{
if (smallest value n= 2)
System.out.prin tln(m);
if (largest value m= 100)
System.out.prin tln (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 : 8Comment
-
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 = 3Comment
-
thank you, you really help me a lot, hopefully ill do good on the testOriginally posted by KiranJyothiTEST 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 = 3Comment
-
I posted the test data. I think it will help you.Originally posted by Rose4msmthank 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.prin tln(n);
{
if (smallest value n= 2)
System.out.prin tln(m);
if (largest value m= 100)
System.out.prin tln (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
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.Comment
-
You are welcome. Hope you do your best in the test. All the very best.Originally posted by Rose4msmthank you, you really help me a lot, hopefully ill do good on the test
KiranJyothiComment
-
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.Originally posted by KiranJyothiYou are welcome. Hope you do your best in the test. All the very best.
KiranJyothiComment
Comment