I have a code that will give me the coordinates of certain points in an array using user input. What code would I add to make the code output say that the address could not be found if the number in the array is not there? I'm pretty sure I need an else statement but I can't get it to work. Here is the code I have right now.
import java.util.Scanner;
public class LabActivityArray
{
public static void main (String[] args)
{
Scanner scanner = new Scanner (System.in);
int rows;
int columns;
int check1,check2;
System.out.println("Enter number of rows: ");
rows = scanner.nextInt();
System.out.println ("Now enter the number of columns: ");
columns = scanner.nextInt();
int[][] array = new int[rows][columns];
System.out.println("Enter the number to start the array: ");
int value = scanner.nextInt();
for (int i = 0; i < rows; i++)
{
for (int j = 0; j < columns; j++)
{
array[i][j]=value++;
System.out.print(array[i][j] + " " );
}
System.out.println();
}
System.out.println("Please give one integer value to be checked in the array: ");
check1 = scanner.nextInt();
System.out.println ("Please give a second integer value to be checked in the array: ");
check2 = scanner.nextInt();
for ( int i = 0; i < rows; ++i )
{
for ( int j = 0; j < columns; ++j )
{
if ( array[i][j] == check1 )
{
System.out.print(array[i][j] + " is located at address array[" + i + "," + j + "]");
}
if ( array[i][j] == check2 )
{
System.out.print("\n" + array[i][j] + " is located at address array[" + i + "," + j + "]");
System.out.println();
}
}
}
}
}
step 1: make a flag say
boolean check1Found = false;
step 2: if you find the value, set the flag to true
if ( array[i][j] == check1 )
{
System.out.print(array[i][j] + " is located at address array[" + i + "," + j + "]");
check1Found = true;
}
step 3: after your loop is finished, print a message if that flag is still false
if(check1Found == false)
{
System.out.println("check 1 not found");
}
You could add two bool flag which are false at first but when the numbers youre searching are found, they are set to true.
bool foundFlag1 = false;
bool foundFlag2 = false;
Then
if ( array[i][j] == check2 ) {
foundFlag2 = true;
..
}
and do the same for check1.
If the flags are false, you know that you couldn't find those inputs!
You are almost right here. Here is the Pseudocode
Initialize Boolean Flag = false;
Search for number in array. if found set Flag = True.
After searching the number in array, check Flag.
If Flag = False, print "the address could not be found"
I would do this:
boolean check1Flag = false;
boolean check2Flag = false;
for ( int i = 0; i < rows; ++i )
{
for ( int j = 0; j < columns; ++j )
{
if ( array[i][j] == check1 )
{
System.out.println(array[i][j] + " is located at address array[" + i + "," + j + "]");
check1Flag = true;
}
if ( array[i][j] == check2 )
{
System.out.println(array[i][j] + " is located at address array[" + i + "," + j + "]");
check2Flag = true;
}
}
}
if(!check1Flag)
{
System.out.println("Can't find " + check1);
}
if(!check2Flag)
{
System.out.println("Can't find " + check2);
}
The flags are set to true when the array is found, so if either are false than that address could not be found.
Related
This question already has answers here:
How do I compare strings in Java?
(23 answers)
Closed 8 years ago.
This is my code for a program that should count the number of each letter in an inputted string. When I run the program, it says that there is 0 of each letter, no matter what I input. Thanks for the help in advance!
import java.util.Scanner;
public class stringprogram {
public static void stringinputmethod()
{
Scanner scan = new Scanner(System.in);
System.out.println("Enter a String");
String strs = scan.nextLine();
int strslength = strs.length();
int numa = 0;
int numb = 0;
int numc = 0;
int numd = 0;
int nume = 0;
int numf = 0;
int numg = 0;
int numh = 0;
int numi = 0;
int numj = 0;
int numk = 0;
int numl = 0;
int numm = 0;
int numn = 0;
int numo = 0;
int nump = 0;
int numq = 0;
int numr = 0;
int nums = 0;
int numt = 0;
int numu = 0;
int numv = 0;
int numw = 0;
int numx = 0;
int numy = 0;
int numz = 0;
for(int i = 0; i <= strslength; i++)
{
if (strs.substring(i, i) == "a")
{
numa = numa + 1;
}
if (strs.substring(i, i) == "b")
{
numb = numb + 1;
}
if (strs.substring(i, i) == "c")
{
numc = numc + 1;
}
if (strs.substring(i, i) == "d")
{
numd = numd + 1;
}
if (strs.substring(i, i) == "e")
{
nume = nume + 1;
}
if (strs.substring(i, i) == "f")
{
numf = numf + 1;
}
if (strs.substring(i, i) == "g")
{
numg = numg + 1;
}
if (strs.substring(i, i) == "h")
{
numh = numh + 1;
}
if (strs.substring(i, i) == "i")
{
numi = numi + 1;
}
if (strs.substring(i, i) == "j")
{
numj = numj + 1;
}
if (strs.substring(i, i) == "k")
{
numk = numk + 1;
}
if (strs.substring(i, i) == "l")
{
numl = numl + 1;
}
if (strs.substring(i, i) == "m")
{
numm = numm + 1;
}
if (strs.substring(i, i) == "n")
{
numn = numn + 1;
}
if (strs.substring(i, i) == "o")
{
numo = numo + 1;
}
if (strs.substring(i, i) == "p")
{
nump = nump + 1;
}
if (strs.substring(i, i) == "q")
{
numq = numq + 1;
}
if (strs.substring(i, i) == "r")
{
numr = numr + 1;
}
if (strs.substring(i, i) == "s")
{
nums = nums + 1;
}
if (strs.substring(i, i) == "t")
{
numt = numt + 1;
}
if (strs.substring(i, i) == "u")
{
numu = numu + 1;
}
if (strs.substring(i, i) == "v")
{
numv = numv + 1;
}
if (strs.substring(i, i) == "w")
{
numw = numw + 1;
}
if (strs.substring(i, i) == "x")
{
numx = numx + 1;
}
if (strs.substring(i, i) == "y")
{
numy = numy + 1;
}
if (strs.substring(i, i) == "z")
{
numz = numz + 1;
}
}
System.out.println("Number of a's: " + numa + "\n" + "Number of b's: " + numb + "\n" + "Number of c's: " + numc + "\n" + "Number of d's: " + numd + "\n" + "Number of e's: " + nume + "\n" + "Number of f's: " + numf + "\n" + "Number of g's: " + numg + "\n" + "Number of h's: " + numa + "\n" + "Number of i's: " + numi + "\n" + "Number of j's: " + numj + "\n" + "Number of k's: " + numk + "\n" + "Number of l's: " + numl + "\n" + "Number of m's: " + numm + "\n" + "Number of n's: " + numn + "\n" + "Number of o's: " + numo + "\n" + "Number of p's: " + nump + "\n" + "Number of q's: " + numq + "\n" + "Number of r's: " + numr + "\n" + "Number of s's: " + nums + "\n" + "Number of t's: " + numt + "\n" + "Number of u's: " + numu + "\n" + "Number of v's: " + numv + "\n" + "Number of w's: " + numw + "\n" + "Number of x's: " + numx + "\n" + "Number of y's: " + numy + "\n" + "Number of z's: " + numz);
}
public static void main(String[] args)
{
stringinputmethod();
}
}
Correct usage of the substring method:
strs.substring(i, i)
needs to be
strs.substring(i, i + 1)
because the char at lastIndex is not included in the output.
Correct comparison of Strings in Java
Also, as pointed out in the comments to this answer, you are comparing Strings with the == operator.
This will only works as long as both your Strings are the same object. For proper comparison you need to use strs.substring(..).equals()
Proper storing of data
Additionally, as already suggested in a comment to your question, you should start using arrays to save data like this.
Instead of
int numa = 0;
....
int numz = 0;
you should use arrays, or even better Map<Character,Integer>.
strs.substring(i, i) == "a" have two problems:
substring(i, i) creates string from i (inclusive), till i (exclusive) which means it creates empty string ""
this is not how we compare Strings. == may work sometimes if strings are pooled, but for dynamically created strings you need to use equals instead of == because Strings are objects, or even better use charAt(i) to get primitive char which you can be able to compare like strs.charAt(i) == 'a' (notice ' instead of ").
You can also use enhanced for loop on array of characters representing your string to avoid charAt. You should probably also be working on lower case characters as pointed in this comment. So your code can look more like
for (char ch : strs.toLowerCase().toCharArray()){
//do something based on value of `ch`
}
Try this:
It is a little bit shorter than your implementation (which is very good, but still a little bit verbose). Use Java 8 with this code, otherwise it won't compile.
What does it do?
If you understand that a string is nothing more but an array you can iterate over that array and see what kind of value is at the given index. The value at this index is put in a map (remember, a map is a key-value-store). So if you put the Integer 1 in the map where its key is "a", that means "a" occurs 1 time.
By reading the values at the appropriate indexii (very sophisticated plural form of index) with HashMap.get("a") and then incrementing the value by one, we have a nice little letter counter... without the need to predefine numa=0 and so forth. Give it a try and let me know if it werx.
package lettercounter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;
/**
*
* #author edm
*/
public class LetterCounter {
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("Enter a String");
String strs = scan.nextLine();
//this map will be populated with the occurrence of the letters in the string.
HashMap<String, Integer> countenLetters = new HashMap<>();
//the next line generates a key-value-store whose key is the letter in the string
//and the value is the accumulated occurrence of said letter.
Arrays.asList(strs.split("")).stream().forEach((String letter) -> {
Integer count = 0;
try {
count = countenLetters.get(letter).intValue();
} catch (Exception e) {
//tried to access a non existing value in the map
//this happens if there is a letter which was not set in the map until now.
//i.e. the first time the letter is encountered.
//this is no error. could have done it with an if also.
}
countenLetters.put(letter, ++count);
});
//do with this stuff what you want;
countenLetters.forEach((k,v) -> {
System.out.println("Letter "+k+" occurs "+v+" times in the string.");
});
}
}
I am new to java and have been trying to write how to search multidimensional arrays. My code works for elements found but when I enter an element that does not match, it does not printout anything. Please tell me what's wrong with my code.
import java.util.Scanner;
public class ArraySearch {
public static void main (String[] args){
Scanner input = new Scanner(System.in);
//lets create the array
int [] [] arrayOfInts = {{1, 2,3,4}, {5,6,7,8},{9,10,11,12}};
//create search variables
System.out.println("Enter the key number to search for in the array: ");
int key = input.nextInt();
boolean foundIt;
//perform search using a for loop
for (int i = 0; i <arrayOfInts.length; i++){
for (int j = 0; j <arrayOfInts[i].length; j++){
if (arrayOfInts[i][j] == key) {
foundIt = true;
if (foundIt) {
System.out.println("found " + key + " at row " +i+ " column " +j);
} else {
System.out.println(key + "is not in the array");
}
}
}
}
}
}
You should initialize your boolean to false, since local variables must be initialized before being used :
boolean foundIt = false;
Otherwise, if the key wasn't found, foundIt would be uninitialized when you access it in your if condition.
Not initializing foundIt should have given you a compliation error (The local variable foundIt may not have been initialized), but you have another error that hid this error. Your if statement that prints the output should be outside the for loops. Now it's inside the condition that finds a match, so it would only be evaluated if you found a match.
You can change your code to following. There are many issues in your code. You have to make correct order of {}, If you do so you needs to initialize foundIt
Scanner input = new Scanner(System.in);
//lets create the array
int[][] arrayOfInts = {{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}};
//create search variables
System.out.println("Enter the key number to search for in the array: ");
int key = input.nextInt();
boolean foundIt = false;
for (int i = 0; i < arrayOfInts.length; i++) {
for (int j = 0; j < arrayOfInts[i].length; j++) {
if (arrayOfInts[i][j] == key) {
System.out.println("found " + key + " at row " + i + " column " + j);
// if found it will change the foundIt to true
foundIt = true;
}
}
}
if (!foundIt) {
System.out.println(key + "is not in the array");
}
Your bracketing is wrong. The if - else statement
if (foundIt) {
System.out.println("found " + key + " at row " +i+ " column " +j);
} else
{System.out.println(key + "is not in the array");
}
Is inside the check of the for loop.
if (arrayOfInts[i][j] == key) {
You probably want to have it inside of the for loop to show the message for each match. But then you should just put a println message inside the if statement in the for loop
if (arrayOfInts[i][j] == key) {
System.out.println("found " + key + " at row " +i+ " column " +j);
And to print the other message when the key was never found, but this has to be done at the end. Make sure you initialize the boolean in the beginning!
boolean foundIt = false;
...
//at the end
if(!foundIt) {
System.out.println("found " + key + " at row " +i+ " column " +j);
}
// perform search using a for loop
for (int i = 0; i < arrayOfInts.length; i++) {
for (int j = 0; j < arrayOfInts[i].length; j++) {
if (arrayOfInts[i][j] == key) {
System.out.println("found " + key + " at row " + i + " column "
+ j);
return;
}
}
}
System.out.println(key + "is not in the array");
I just added a return on finding the desired element and cut/paste the else branch to the end of the loop.
Your System.out is only inside this if-block
if (arrayOfInts[i][j] == key)
so if you don't find something the is no printout
I would do it in this way:
...
for (int i = 0; i <arrayOfInts.length; i++){
for (int j = 0; j <arrayOfInts[i].length; j++){
if (arrayOfInts[i][j] == key) {
foundIt = true;
// Tell where you found it
System.out.println("found " + key + " at row " +i+ " column " +j);
}
}
}
// After all check whether you found something anytime
if(!foundIt){
System.out.println(key + "is not in the array");
}
...
It's because your print statements the if (foundIt) ... else block is within the if (arrayOfInts[i][j] == key) block. This means that if the int is not found, the code never enters that inner if check where you print.
You can move the "not found" to the end.
For example:
boolean foundIt = false;
// perform search using a for loop
for (int i = 0; i < arrayOfInts.length; i++)
{
for (int j = 0; j < arrayOfInts[i].length; j++)
{
if (arrayOfInts[i][j] == key)
{
foundIt = true;
System.out.println("found " + key + " at row " + i + " column " + j);
}
}
}
if (!foundIt)
{
System.out.println(key + "is not in the array");
}
Don't forget to initialize the foundIt to false first.
My Suggested Solution is :
bool foundit=false;
for (int i = 0; i <arrayOfInts.length; i++){
for (int j = 0; j <arrayOfInts[i].length; j++){
if (arrayOfInts[i][j] == key)
{
foundIt = true;
break;
System.out.println("found " + key + " at row " +i+ " column " +j);
}
}
}
if(!foundit)
{
system.out.println("Key not found in the array.")
}
This works:
import java.util.Scanner;
public class ArraySearch {
public static void main (String[] args){
Scanner input = new Scanner(System.in);
//lets create the array
int [] [] arrayOfInts = {{1, 2,3,4}, {5,6,7,8},{9,10,11,12}};
//create search variables
System.out.println("Enter the key number to search for in the array: ");
int key = input.nextInt();
//perform search using a for loop
for (int i = 0; i <arrayOfInts.length; i++){
for (int j = 0; j <arrayOfInts[i].length; j++){
if (arrayOfInts[i][j] == key) {
System.out.println("found " + key + " at row " +i+ " column " +j);
return;
}
}
}
System.out.println(key + " is not in the array");
}
}
Why:
commands in operatorif (arrayOfInts[i][j] == key) {} executing only if the element is found in array, so it is no need to use your boolean foundIt;. Use return to end executing the class, cos we have found what we wanted. The line System.out.println(key + " is not in the array"); should be after the two cycles so it will work only if we've checked each element of the two-dimensional array before.
I am having a problem with my loop and I realise there is probably a slight adjustment needs to be made to get this working the right way but I just cant see what that is! I have included the code below:
final int SIZE = 6;
//array to store user numbers
int [] userNumbers = new int[SIZE];
boolean found = false;
int pos = 0;
boolean bonus = false;
int lottCount = 0;
while (pos<SIZE)
{
System.out.println("enter your numbers");
userNumbers[pos]=keyboard.nextInt();
pos++;
}
for (int count: userNumbers)
{
System.out.println(count);
}
for (int loop = 0; loop <numbers.length; loop++ )
{
for (int loopOther = 0; loopOther < SIZE; loopOther++)
{
if (userNumbers[loop] == numbers[loopOther])
lottCount++;
}
if (userNumbers[loop] == bonusBall)
{
bonus = true;
System.out.println("You have matched " + lottCount + " numbers " + "and" + " the bonus ball" + bonusBall);
}
else
{
System.out.println("You have not won at this time");
}
}
System.out.println("You have matched " + lottCount + " numbers");
The ouput looks like this:
15
16
17
18
19
43
You have not won at this time
You have not won at this time
You have not won at this time
You have not won at this time
You have not won at this time
You have matched 1 numbers the bonus ball43
You have matched 1 numbers
I only want the program to inform me of each condition once. can anyone help me with this? Thanks in advance
for (int loop = 0; loop <numbers.length; loop++ )
{
for (int loopOther = 0; loopOther < SIZE; loopOther++)
{
if (userNumbers[loop] == numbers[loopOther])
lottCount++;
}
if (userNumbers[loop] == bonusBall)
{
bonus = true;
}
}
if (bonus)
{
System.out.println("You have matched " + lottCount + " numbers " + "and" + " the bonus ball" + bonusBall);
}
else
{
System.out.println("You have not won at this time");
}
Or shorter:
for (int number : numbers)
{
for (int userNumber : userNumbers)
{
if (userNumber == number)
lottCount++;
}
if (userNumber == bonusBall)
{
bonus = true;
}
}
if (bonus)
{
System.out.println("You have matched " + lottCount + " numbers " + "and" + " the bonus ball" + bonusBall);
}
else
{
System.out.println("You have not won at this time");
}
Hi, I'm trying to learn Java slowly, but I'm having trouble with a infinite loop. Below is my code. From the start of the constructor until the end of the display method, how do I go about making the loop stop after the last entry added?
public UnitResults(int Size, String title)
{
this.fName = new String [Size];
this.surname = new String [Size];
this.Marks = new int [Size];
pointer = 0;
fName[pointer] = "Daniel";
surname[pointer] = "Scullion";
Marks[pointer] = 60;
unitTitle = title;
pointer ++;
}
public Boolean add( String tempfName, String tempsName, int newGrade)
{
if (pointer == fName.length)
{
System.out.println("The Students Database is full");
return false;
}
else
{
fName [pointer] = tempfName;
surname [pointer] = tempsName;
Marks[pointer] = newGrade;
pointer ++;
System.out.println("Student Added");
return true;
}
} // end Add
public void display()
{
System.out.println("Students Results\n");
for (int index = 0; index < pointer; index++)
{
System.out.println( unitTitle + "\n"
+ fName[index] + "\n"
+ surname[index] + "\n"
+ Marks[index] + "\n"
+ "\n" );
index++;
}
}
Thanks for any help with this!
The index++; line is not required and indeed is probably the cause of your infinite loop. The index++ is already specified in the for() statement. Adding is again means that index is incremented by 2 for each loop.
for (int index=0; index < pointer; index ++)
{
System.out.println( unitTitle + "\n"
+ fName[index] + "\n"
+ surname[index] + "\n"
+ Marks[index] + "\n"
+ "\n" );
index++; // <<<----- this line should not be here
}
Here is the main problem:
java.util.NoSuchElementException: No line found
at java.util.Scanner.nextLine(Unknown Source)
at ExamAnalysis.main(ExamAnalysis.java:21)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at edu.rice.cs.drjava.model.compiler.JavacCompiler.runCommand(JavacCompiler.java:271)
The program compiles and runs. It's just that I am either getting the java.util.NoSuchElementException along with my five jother errors with (answer.charAt(i) == char) near the bottom. Here is my program:
import java.io.*;
import java.util.Scanner;
class ExamAnalysis
{
public static void main(String [] args) throws FileNotFoundException
{
Scanner keyboard = new Scanner(System.in);
System.out.println("Please type the correct answers to the exam questions, one right after the other: ");
String answers = keyboard.nextLine();
System.out.println("Where is the file with all the student responses? ");
String responses = keyboard.nextLine();
Scanner read = new Scanner(new File(responses));
while (read.hasNextLine())
{
for (int i = 0; i <= 10; i++)
{
responses = read.nextLine();
int p = 1;
p += i;
System.out.println("Student " + p + " responses: " + responses.substring(0,10));
}
System.out.println("Thank you for the data on 9 students. Here's the analysis: ");
resultsByStudents(responses, answers);
analysis(responses);
}
}
public static void resultsByStudents(String responses, String answers)
{
System.out.println ("Student # Correct Incorrect Blank");
System.out.println ("~~~~~~~~~ ~~~~~~~ ~~~~~~~~~ ~~~~~");
int student = 0;
int correct = 0;
int incorrect = 0;
int blank = 0;
for (int i = 0; i <= 9; i++)
{
for (int j = 0; j <= responses.length(); j++)
{
if ((responses.charAt(j)) == answers.charAt(j))
correct++;
else if ((responses.charAt(j)) != answers.charAt(j))
incorrect++;
else
blank++;
}
System.out.println(student + " " + correct + " " + incorrect + " " + blank);
student++;
}
}
public static void analysis(String responses)
{
System.out.println("QUESTION ANALYSIS (* marks the correct response)");
System.out.println("~~~~~~~~~~~~~~~~~");
//stores the percentage of each choice chosen
double A = 0;
double B = 0;
double C = 0;
double D = 0;
double E = 0;
double X = 0;
// tallys every variable chosen per question
for (int i = 0; i <= 10; i++) // go through all the questions
{
for (int j = 0; j <= responses.charAt(i); j++) //go through all the student responses
{
// variable that are being tallied
int chooseA = 0;
int chooseB = 0;
int chooseC = 0;
int chooseD = 0;
int chooseE = 0;
int chooseBlank = 0;
//variables take percentage of choices that have been chosen from each student
A = chooseA/9;
B = chooseB/9;
C = chooseC/9;
D = chooseD/9;
E = chooseE/9;
X = chooseBlank/9;
// variables that will print the asterisk with certain character of correct answer
String a = "A";
String b = "B";
String c = "C";
String d = "D";
String e = "E";
String blank = "blank";
if (responses.charAt(j) == A)
chooseA++;
else if (responses.charAt(j) == B)
chooseB++;
else if (responses.charAt(j) == C)
chooseC++;
else if (responses.charAt(j) == D)
chooseD++;
else if (responses.charAt(j) == E)
chooseE++;
else
chooseBlank++;
System.out.println("Question #" + i);
if (answers.charAt(i) == 'A') a = "A*"; // answers cannot be resolved(I already made it a global variable in my main method.)
else if (answers.charAt(i) == 'B') b = "B*";// answers cannot be resolved
else if (answers.charAt(i) == 'C') c = "C*";// answers cannot be resolved
else if (answers.charAt(i) == 'D') d = "D*";// answers cannot be resolved
else if (answers.charAt(i) == 'E') e = "E*";// answers cannot be resolved
System.out.println(a + " " + b + " " + c + " " + d + " " + e + " " + blank);
System.out.println (chooseA + " " + chooseB + " " + chooseC + " " + chooseD + " " + chooseE + " " + chooseBlank );
System.out.println (A + " " + B + " " + C + " " + D + " " + E + " " + X);
}
}
}
}
while (read.hasNextLine())
{
for (int i = 0; i <= 10; i++)
{
responses = read.nextLine();
int p = 1;
p += i;
System.out.println("Student " + p + " responses: " + responses.substring(0,10));
}
System.out.println("Thank you for the data on 9 students. Here's the analysis: ");
resultsByStudents(responses, answers);
analysis(responses);
}
}
Your logic here is confusing you. read.nextLine(); "Advances this scanner past the current line and returns the input that was skipped. This method returns the rest of the current line, excluding any line separator at the end. The position is set to the beginning of the next line."
So you are saying, does it have a line? If so, read the next 10...well...11 lines, which isn't what you want. You don't know if there are 11 lines past this point. Don't know what that text file looks like, but you will want to restructure this part to either say, "While it has a next line", or "Read 11 lines"
Remove the for loop may resolve the issue. You are checking only once by using while(hasNextLine() ) but calling read.nextLine() 10 times in for loop.
for (int i = 0; i <= 10; i++)
{
responses = read.nextLine();
.......
}
int i = 0;
int numberOfStudents = 9;
while (i < numberOfStudents && read.hasNextLine()){
responses = read.nextLine();
i++;
System.out.println("Student " + i + " responses: " + responses.substring(0,10));
}
System.out.println("Thank you for the data on "+ numberOfStudents +" students. Here's the analysis: ");
resultsByStudents(responses, answers);
analysis(responses);
i < numberOfStudents : makes the required number of inserts
read.hasNextLine() : checks if there is input from console. If not the program waits for input.
for (int i = 0; i <= 10; i++)
count from 0 -> 10 = 11 students