PDA

View Full Version : Java program with arrays


looking_to_code
11-03-2009, 08:13 AM
I am taking a programming concepts class and have to write a program in Java. The program should prompt the teacher to input a student number. The quiz score for that student will be displayed. The program can prompt for each quiz score or the scores can be preloaded or hard-coded into the program. Your solution must include an array. This program is not part of the grade i need it so i can write a paper on the concepts in each line.

This is what i have so far
Import java.until. ;
Class Myprogram. ;
Public static void main (String [] args ) ;
Int Student Number ;
Student Nunber=22 ;
Scanner input = new Scanner( System.in );

kwhubby
11-03-2009, 12:14 PM
Hello looking_to_code,
First of all, you've made quite a few typos in the tiny bit of code you provided.

Note the code I posted:



import java.io.*;
import java.util.Scanner;
import java.util.Arrays;
class Myprogram {
public static void main (String[] args) {
int StudentNumber;
StudentNumber=22;
int score[] = {50,20,45,82,25,63};
Scanner input = new Scanner(System.in);
}
}


It's best to avoid importing all of java.util so I imported Scanner and Arrays from util. You can import all with java.util.Scanner.*

I added an array score[] with some example scores. This is the basis for something that will work quite easily if student numbers are sequential (1,2,3,4,5 ...)
You are going to need to add code to prompt for the student number and then code to print the corresponding value in the array.