Answer:
The answer to this question can be given as
The potential problem with the loop is it's counts when the user enters -1 from the keyboard, so the count will too many.
Explanation:
In the program there some line is missing. So the right program of the question can be given as:
import java.util.*; //import package for take input from user.
public class Main //define main class.
{
public static void main(String[] args)//define main function
{
Scanner scan=new Scanner(System.in); //creating object.
//print values.
System.out.print("Enter integers. Enter -1 to exit.");
System.out.println(" Count of integers entered will be returned.");
int n=0,c=0; //declaring integer variable.
while (n != -1) //loop
{
n = scan.nextInt(); //take input by user and hold on variable n.
c++;
}
System.out.println(c); //print value.
}
}
output:
Enter integers. Enter -1 to exit. Count of integers entered will be returned.
-1
1
Answer:
Cell Phone, ATM Cash Machine, and a GPS Mapping Device
Answer:
Read the file and save it to a variable as a string, split the string variable and cast it to a set object using the set function to get the unique words in the file. Then use the max function with the key attribute to use regular expression module "re" to compare the first letter of each item to return in a list comprehension or append to a list.
Explanation:
The open function is used to import a file in python, the split string method splits the string to a list of items and the set function removes any duplicates of a word or item.
Using the for loop statement, iterate over the items and compare and return the items in alphabetical order with the 're' search method getting the item with uppercase letters with higher precedence than lowercase.
Answer:
for (int i = 0; i < 9; ++i)
{
int k = 0;
while (k < 20 && scotus[i][k] != '')
{
cout << scotus[i][k];
k++;
}
cout << "\n";
}
Explanation:
scotus here is a two dimensional array. It contains names of 9 justices. so the loop starts from 0 and ends when i points to the last name element in the array. Then a while loop is used to check that name is longer than twenty characters and will keep on printing each output on the separate line.
Another way to write this:
for (int i = 0; i < 9; i++){
cout << scotus[i] << "\n";
}
This loop will keep on executing and printing the names of the nine justices at every iteration until it reaches the end of the array (last element of the array scotus).