Posted by: techGuy April 1, 2008
HELP HELP
Login in to Rate this Post:     0       ?        

ke ho mitra!! hope u r not  a computer student, ok this is what u do, and this is java so deosnt matter wheather its notebook, or desktop or linux, or windows. So, hope you have atleast run  "Hello world " program in your notebook ever.

1. Create a file with the info ur teacher asked u to enter. Save it as file.txt in c: (Hope I dont have to teach you this)

m   3.5

f     2.5

f    4.0

2. Create one file and copy paste the below code in that  and save it as jayNepal.java

import java.io.*;

public class jayNepal

{

public static void main(String[] args)

{

//..initialize

String sex="";

//..total marks of male

double mMarks=0.0;

//..total number of male student

int mCount=0;

//.. total marks of female

double fMarks=0.0;

//.. total number of female

int fCount=0;

double marks;

try {

BufferedReader in = new BufferedReader(new FileReader("c:\\file.txt"));

String str;

while ((str = in.readLine()) != null)

{

int spacePosition=str.indexOf(" ");

sex=str.substring(0, spacePosition);

marks=Double.parseDouble(str.substring(spacePosition+1));

System.out.println("sex "+ sex + " and marks " + marks);

if(sex.equals("m") || (sex.equals("M")))

{

mMarks=mMarks+marks;

mCount++;

}

else

{

fMarks=fMarks+marks;

fCount++;

}

}

System.out.println("Average male GPA is " + mMarks/mCount +" Average Female GPA is " + fMarks/fCount);

in.close();

}

catch (IOException e)

{

}

}

}

3. compile this code

javac jayNepal.java

4. run jayNepal using

java jayNepal

Read Full Discussion Thread for this article