View StudentPoll.java
// Fig. 7.8: StudentPoll.java | |
// Poll analysis program. | |
public class StudentPoll { | |
public static void main( String[] args ) { | |
// student response array (more typically, input at runtime) | |
int[] responses = { 1, 2, 5, 4, 3, 5, 2, 1, 3, 3, 1, 4, 3, 3, 3, 2, 3, 3, 2, 14 }; | |
int[] frequency = new int[ 6 ]; // array of frequency counters | |
// for each answer, select responses element and use that value | |
// as frequency index to determine element to increment |
View BarChart.java
// Fig. 7.6: BarChart.java | |
// Bar chart printing program. | |
public class BarChart { | |
public static void main( String[] args ) { | |
int[] array = { 0, 0, 0, 0, 0, 0, 1, 2, 4, 2, 1 }; | |
System.out.println( "Grade distribution:" ); | |
// for each array element, output a bar of the chart |
View bonfire-return-largest-numbers-in-arrays.js
// Bonfire: Return Largest Numbers in Arrays | |
// Author: @gulzaar | |
// Challenge: http://www.freecodecamp.com/challenges/bonfire-return-largest-numbers-in-arrays | |
// Learn to Code at Free Code Camp (www.freecodecamp.com) | |
function largestOfFour(arr) { | |
// You can do this! | |
var mNum = new Array(); |