Thanks a lot Sergey for helping out. I appreciate your response
I have yet another question please, I am trying my hands on some of my own
exercise in the while do class, and two have been giving me concerns
I am trying to fill an array elements with user inputs using the
JOptionPane.showInputDialog method and a while loop, I convert the input
with the Integer.parseInt method when received. and then I perform an
operation on each received array, then I try to output the array elements
in a JOptionPane.showMessageDialog. but I dont get any message in the
result, could you help me look at what is wrong?
import javax.swing.JOptionPane;
public class TestingDifferentLogic {
public static void main(String[] args) {
String[] names = { "" , "" , ""};
int English[] = {1,2,3};
int Math[] = {1,2,3};
int Geography[] = {1,2,3};
int TotalScore[] = {1,2,3};
int i = 1;
//for (int i = 0; i < 3 ; i++)
while (i < 4)
{ names [i]= JOptionPane.showInputDialog("Please enter your name");
English [i] = Integer.parseInt(JOptionPane.showInputDialog("Please
enter English score"));
Math [i] = Integer.parseInt(JOptionPane.showInputDialog("Please
enter Math score"));
Geography [i] = Integer.parseInt(JOptionPane.showInputDialog("Please
enter Geography score"));
TotalScore [i] = English[i] + Math[i] + Geography[i];
// Secondname = names [1];
i++;
}
JOptionPane.showMessageDialog(null, "The second person is " + names
[1] + " and his score is " + TotalScore [1]);
}
}
My second question is to know if there is a math function that can take a
score, compare it with other scores and get the number position, for
example I input 20,30,40,60 at keyboard, and the function will look through
the four array and tell me number 30 ( which was second input) is 3rd
highest number in the list, or the second lowest number. not just to give
me highest or lowest but 1st, 2nd, 3rd 4th etc highest or lowest.
I am trying an exercise that will perform mathematical operation on student
result and tell them their grade in each subject and grade per class
I hope my questions are not too many, bear with me as I am just starting
the java journey.
On Friday, 26 December 2014 09:03:34 UTC+1, Sergey Radov wrote:
>
> Hello kareem,
>
> By my humble opinion, it was a support of good programming style , e.g.
> declaring variables before usage. Unfortunately, java doesn't initiate
> variables automatically. So we made it equal to empty string ("") ;
> I would work if you type at line 14) String name =dataIn.readLine(); also
> but doing so, you make your code difficult to read by others.
> In this example, we created empty string variable and than replaced it by
> other variable using readLine.
>
> Sang, sorry for answering instead of you.
>
>
> On Thursday, December 25, 2014 8:04:04 PM UTC+2, kareem ashiru wrote:
>>
>> Hi Sang,
>>
>> I am just at the elementary level in the Java tutorials( first course), I
>> have some question or a little more insight into the logic. In the sample
>> code for bufferedReader shown below:
>>
>> 1 import java.io.BufferedReader;
>> 2 import java.io.InputStreamReader;
>> 3 import java.io.IOException;
>> 45
>> public class GetInputFromKeyboard {
>> 67
>> public static void main( String[] args ){
>> 8 BufferedReader dataIn = new BufferedReader(
>> 9 new InputStreamReader( System.in) );
>> 10
>> 11 String name = "";
>> 12 System.out.print("Please Enter Your Name:");
>> 13 try{
>> 14 name = dataIn.readLine();
>> 15 }catch( IOException e ){
>> 16 System.out.println("Error!");
>> 17 }
>> 18 System.out.println("Hello " + name +"!");
>> 19 }
>> 20 }
>>
>>
>> we created a new variable to hold the new instance of BufferedReader
>> class :" dataIn"
>> I am not sure I understand why we need to create a new string variable
>> again : "name" and then equate "name" to "dataIn"
>>
>> My second question is, I think the readLine() method does the same thing
>> as code number 8 and 9, if not whats the difference.
>>
>> regards
>>
>
--
You received this message because you are subscribed to the Google Groups
"JPassion.com: Java Programming" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
Visit this group at http://groups.google.com/group/jpassion_java.
For more options, visit https://groups.google.com/d/optout.