cs106a code snippet - transl to - javaSE (stanford java -into- standard java)
import static java.lang.System.out; //import static java.lang.Math.random; import java.util.Scanner; import java.util.Arrays;
public class Stanf_16 implements Runnable{
//Static Field Constants: private static final int MAX_SIZE = 5; private static final int SENTINEL = -1;
// readInt equivalent: userInput + hasNextInt() + nextInt() static Scanner userInput = new Scanner(System.in);
Stanf_16(){ super(); } public static void main(String[] argzilla){ Stanf_16 s = new Stanf_16(); s.run(); userInput.close(); //closes resources }//close main public void run(){ int[] testN = new int[MAX_SIZE]; int numScores = 0; //int x = (int)(random() * 5); while(true){ out.print("Enter a test score: "); if(userInput.hasNextInt()){ int score = userInput.nextInt(); if(score == SENTINEL) break; testN[numScores++] = score; //Assign each new userInput score to an //index in the array (1st) & then (post) increment the index by 1 (after)
}//close if }//close while out.println(Arrays.toString(testN)); }//close run }//close class
//========== lect16 code snippet:
public void run(){
int[] mid= new int[MAX_SIZE];
int numScores = 0;
while(true){
int score = readInt( “ ? “);
if(score== SENTINEL) break;
mid[numScores++] = score;
}
}











