Start New Discussion within our Software Development Community

i want to write a a program that will accept student name and grades and output it.use an array data structure in the implementation this program and implement the following

write method that will traverses the array and allow the user to perform the following processes

a) search for a particular student and his or her marks
b)find the average of all the student in the class
c)find all student with a mark below 50 and output them.

i started off with this codes

import java.util.Scanner;
//import java.lang.String;
public class Main {
public static int n;
//public static String names;
//private static String[] nameS;
//private static String[] nameS;
/**
* @param args the command line arguments
*/

public static void main(String[] args/*,String[] nameS*/) {
Scanner in=new Scanner(System.in);
int Da=0;
int num []=new int[n];
//int x=0;


System.out.printf("%s\n","Enter the Number of student taking This Couse");
n=in.nextInt();
String name[]=new String [n];
System.out.printf("%s %s \n", "index","value");
for (; Da < name.length; Da++ )/*Da 4 Display array*/ {
System.out.printf( "%5d%8d\n", Da, name[Da] );
}
System.out.println("Enter the names of the student");
String names;
names=in.nextLine();
name[n] = new String(names);
for (; Da < name.length; Da++ ){
System.out.printf( "%5d%8d\n", Da, name[Da] );
}


}
}

i can not input the names into the array( name) i created
pls help me

I would use a for loop to fill the array with names.Maybe something like:

for(int i = 0, i < names.length(); i++)
   // ask user to input string 
   // store the string in names[i]

From your code, it looks like you have a good idea of well arrays and for loops work together, since you are using them for you printf commands. It's the same idea as that, except you are filling the array instead of printing it. I hope that helps.

This article has been dead for over six months. Start a new discussion instead.