1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Ainat [17]
3 years ago
9

Assume inputFile is a Scanner object used to read data from a text file that contains a number of lines. Each line contains an a

rbitrary number of words, with at least one word per line. Select an expression to complete the following code segment, which prints the last word in each line. while (inputFile.hasNextLine()) { String word = ""; String line = inputFile.nextLine(); Scanner words = new Scanner(line); while (_________________) { word = words.next(); } System.out.println(word); }
Computers and Technology
1 answer:
anzhelika [568]3 years ago
7 0

Answer:

words.hasNext()

Explanation:

Given the code snippet below:

  1.        while (inputFile.hasNextLine()) {
  2.            String word = "";
  3.            String line = inputFile.nextLine();
  4.            Scanner words = new Scanner(line);
  5.            while (words.hasNext()) {
  6.                word = words.next();
  7.            }
  8.            System.out.println(word); }
  9.    }

We have a inputFile Scanner object that can read data from a text file and we presume the inputFile has read several rows of data from the text file. So long as there is another line of input data available, the outer while loop will keep running. In each outer loop, one line of data will be read and assign to line variable (Line 3). Next, there is another Scanner object, words, which will take the current line of data as input. To get the last word of that line, we can use hasNext() method. This method will always return true if there is another tokens in its input. So the inner while loop will keep running so long as there is a token in current line of data and assign the current token to word variable. The word will hold the last token of current line of data upon exit from the inner loop. Then we can print the output (Line 8) which is the last word of the current line of data.

You might be interested in
The (X , y) coordinates of a certain object as a function of time' are given by Write a program to determine the time at which t
ra1l [238]

Answer:

t = [0:0.01:4];

x = 5*t - 10;

y = 25442 - 120*t + 144;

d = x.^2 + y.^2;

min = 1e+14;

for k = 1:length(t)

if d(k) < min

min = da(k);

tmin = t(k);

end

end

disp('The minimum distance is: ')

disp(sqrt(min))

disp('and it occurs at t = ')

disp(tmin)Output:

>> withLoop

The minimum distance is:

2.5106e+04

and it occurs at t =

4

Explanation:

4 0
3 years ago
Note: You can use a word document to write your answers and copy-paste your answer to the area specified. a. (5 points) Convert
MrMuchimi

Answer:

EA9_{16} = 3753

CB2_{16} = 3250

(1011 1110 1101 1011 1010)_2 = 781754

(1010 1000 1011 1000 1110 1101)_2 = 11057389

(1011 1110 1101 1011 1010)_2 = BEDBA

(1010 1000 1011 1000 1110 1101)_2 =  A8B8ED

74510_8= 221416

67210_8 = 203212

Explanation:

Solving (a): To base 10

(i)\ EA9_{16

We simply multiply each digit by a base of 16 to the power of their position.

i.e.

EA9_{16} = E * 16^2 + A * 16^1 + 9 * 16^0

EA9_{16} = E * 256 + A * 16 + 9 * 1

In hexadecimal

A = 10; E = 14

So:

EA9_{16} = 14 * 256 + 10 * 16 + 9 * 1

EA9_{16} = 3753

(ii)\ CB2_{16}

This gives:

CB2_{16} = C * 16^2 + B * 16^1 + 2 * 16^0

CB2_{16} = C * 256 + B * 16 + 2 * 1

In hexadecimal

C = 12; B =11

So:

CB2_{16} = 12 * 256 + 11 * 16 + 2 * 1

CB2_{16} = 3250

Solving (b): To base 10

(i)\ (1011 1110 1101 1011 1010)_2

We simply multiply each digit by a base of 2 to the power of their position.

i.e.

(1011 1110 1101 1011 1010)_2 = 1 * 2^{19} + 0 * 2^{18} + 1 * 2^{17} + 1 * 2^{16} +1 * 2^{15} + 1 * 2^{14} + 1 * 2^{13} + 0 * 2^{12} + 1 * 2^{11} + 1 * 2^{10} + 0 * 2^9 + 1 * 2^8 +1 * 2^7 + 0 * 2^6 + 1 * 2^5 + 1 * 2^4 + 1 * 2^3 + 0 * 2^2 + 1 * 2^1 + 0 * 2^0

(1011 1110 1101 1011 1010)_2 = 781754

(ii)\ (1010 1000 1011 1000 1110 1101)_2

(1010 1000 1011 1000 1110 1101)_2 = 1 * 2^{23} + 0 * 2^{22} + 1 * 2^{21} + 0 * 2^{20} +1 * 2^{19} + 0 * 2^{18} + 0 * 2^{17} + 0 * 2^{16} + 1 * 2^{15} + 0 * 2^{14} + 1 * 2^{13} + 1 * 2^{12} +1 * 2^{11} + 0 * 2^{10} + 0 * 2^9 + 0 * 2^8 + 1 * 2^7 + 1 * 2^6 + 1 * 2^5 + 0 * 2^4 + 1*2^3 + 1 * 2^2 + 0 * 2^1 + 1 * 2^0

(1010 1000 1011 1000 1110 1101)_2 = 11057389

Solving (c): To base 16

i.\ (1011 1110 1101 1011 1010)_2

First, convert to base 10

In (b)

(1011 1110 1101 1011 1010)_2 = 781754

Next, is to divide 781754 by 16 and keep track of the remainder

781754/16\ |\ 48859\ R\ 10

48859/16\ |\ 3053\ R\ 11

3053/16\ |\ 190\ R\ 13

190/16\ |\ 11\ R\ 14

11/16\ |\ 0\ R\ 11

Write out the remainder from bottom to top

(11)(14)(13)(11)(10)

In hexadecimal

A = 10; B = 11; C = 12; D = 13; E = 14; F = 15.

(11)(14)(13)(11)(10)=BEDBA

So:

(1011 1110 1101 1011 1010)_2 = BEDBA

ii.\ (1010 1000 1011 1000 1110 1101)_2

In b

(1010 1000 1011 1000 1110 1101)_2 = 11057389

Next, is to divide 11057389 by 16 and keep track of the remainder

11057389/16\ |\ 691086\ R\ 13

691086/16\ |\ 43192\ R\ 14

43192/16\ |\ 2699\ R\ 8

2699/16\ |\ 168\ R\ 11

168/16\ |\ 10\ R\ 8

10/16\ |\ 0\ R\ 10

Write out the remainder from bottom to top

(10)8(11)8(14)(13)

In hexadecimal

A = 10; B = 11; C = 12; D = 13; E = 14; F = 15.

(10)8(11)8(14)(13) = A8B8ED

So:

(1010 1000 1011 1000 1110 1101)_2 =  A8B8ED

Solving (d): To octal

(i.)\ 74510

Divide 74510 by 8 and keep track of the remainder

74510/8\ |\ 9313\ R\ 6

9313/8\ |\ 1164\ R\ 1

1164/8\ |\ 145\ R\ 4

145/8\ |\ 18\ R\ 1

18/8\ |\ 2\ R\ 2

2/8\ |\ 0\ R\ 2

Write out the remainder from bottom to top

74510_8= 221416

(ii.)\ 67210

Divide 67210 by 8 and keep track of the remainder

67210/8\ |\ 8401\ R\ 2

8401/8\ |\ 1050\ R\ 1

1050/8\ |\ 131\ R\ 2

131/8\ |\ 16\ R\ 3

16/8\ |\ 2\ R\ 0

2/8\ |\ 0\ R\ 2

Write out the remainder from bottom to top

67210_8 = 203212

8 0
3 years ago
What are the default left and right margins in Word? ​
Serga [27]

Answer:

The default margins for Microsoft Word from version 2007 onward have been 1 inch (25.4 mm) all around; in Word 2003, the default top and bottom margins were 1 inch (25.4 mm), but 1.25 inches (31.7 mm) were given at the left and the right.

6 0
3 years ago
Read 2 more answers
What are an administrator's choices for managing file permissions on a drive formatted as fat32?
Alexeev081 [22]
<span>If the drive is a network share, then Share permissions can be used.</span>
6 0
4 years ago
-) An attribute is a(n)?
Anarel [89]
<h3>An attribute is a characteristic.In a data base management system,an attribute refers to a database component,such as a table.It also may refer to a database field.</h3>

6 0
3 years ago
Other questions:
  • Use the following business rules to assign name to the tables on the ERD: Note: These rules are in the context of a small retail
    7·1 answer
  • What is the speed limit in school zone
    11·2 answers
  • What is important for an internet user to know about https:// ?
    9·1 answer
  • Find 5 rational numbers between -1 and 1​
    8·1 answer
  • Write a program that prompts the user for an integer and then prints all prime numbers up to that integer.
    7·1 answer
  • How can I watch you-tube on my school computer without it being blocked on the computer when it uses Lightspeed Systems Relay or
    7·1 answer
  • Create a parent class called Shape with width and height parameters of type double and a function that returns the area of the s
    12·1 answer
  • Написати лабараторну, на тему:Вивчення властивостей та застосування шаруватих пластиків та кермаміки
    13·1 answer
  • Which of these is NOT an example of a GUI?
    7·1 answer
  • Write a Python function that join the two string and print it ​
    14·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!