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
Ksju [112]
3 years ago
5

You coded the following class:

Computers and Technology
1 answer:
Oxana [17]3 years ago
8 0

Answer:

The code above tries to read a file using the scanner class in java programming language.

But it was done properly.

First, the scanner class library is not imported to the program.

Second,the syntax used in this program is an invalid way of reading a file in java programming language using the scanner class.

Lastly, "String s = file.nextLine();" is not a proper way of reading each line

To correct this problem; use the following code;

import java.util.Scanner;

import java.io.File;

import java.io.FileNotFoundException;

public class ReadFileWithScanner {

try

{

public static void main(String args[]) throws FileNotFoundException {

File text = new File("data.txt");

Scanner file = new Scanner(text);

int lines = 1;

while(file.hasNextLine()){

String line = filw.nextLine();

System.out.println("line " + lines + " :" + line);

lines++;

}

catch (ArithmeticException ae)

{

System.out.println(ae.getMessage());

}

}

}

You might be interested in
Write a constructor for BaseballPlayer. The constructor takes three int parameters: numHits, numRuns, and numRBIs storing the va
Monica [59]

Answer:

Following are the code to the given question:

public class BaseballPlayer//defining a class BaseballPlayer

{

BaseballPlayer(int numHits, int numRuns, int numRBIs)//defining a parameterized cons

{

}

}

Explanation:

Some of the data is missing, which is why the solution can be represented as follows:

In this code, a class BaseballPlayer is defined, and inside the class a parameterized constructor is defined that holds three integer variable "numHits, numRuns, and numRBIs".

5 0
3 years ago
Write the function longest that, given a nonempty list of strings, finds the longest even-length string that ends with ing. It t
lorasvet [3.4K]

Answer:

  1. def longest(L):
  2.    for x in L:
  3.        if(len(x) % 2 == 0):
  4.            if(x.endswith("ing")):
  5.                return x  
  6.    return ""
  7. print(longest(["Playing", "Gaming", "Studying"]))

Explanation:

The solution is written in Python 3.

Firstly, create a function longest that takes one parameter L as required by question (Line 1).

In the function, create a for loop to traverse through each string in L and check if the current string length is even (Line 2 - 3). If so, use string endwiths method to check is the current string ended with "ing". If so return the string (Line 4-5).

At last, test the function by passing a list of string and we shall get the output "Gaming".

8 0
3 years ago
Powerpoint assumes that the first slide in a new presentation is the
fomenos
Powerpoint assumes that the first slide in a new presentation is the title slide
5 0
3 years ago
What is a best practice when approaching an automation effort?
Sauron [17]
Not sure bro. What’s the question reslly about?
5 0
3 years ago
Which of the following dimensions of e-commerce technology has the potential to raise the quality of information? A) Global reac
masya89 [10]

Answer:

D. Information density.

Explanation:

E-commerce is the online trading of goods and service between a buyer and a seller, with integrated payment medium. This website technology provides an e-store and needs information on the client data to provide the necessary services.

Information density is the total amount and quantity of information available to all participating in e-commerce. This provides a rich quality and database of information for e-commerce website technology, to enhance the quality of services in e-commerce, information density must be considered.

7 0
3 years ago
Other questions:
  • Suppose you wish to write a method that returns the sum of the elements in partially filled array. Which is the best choice for
    6·1 answer
  • A university wants to install a client-server network. Which feature do you think is important for them as they set up the netwo
    8·1 answer
  • Explain at least one reason why programming languages have functions
    12·1 answer
  • A motherboard has four DIMM slots; three slots are gray and the fourth is black. What type of memory is this board designed to u
    6·1 answer
  • This is important I need help please
    14·1 answer
  • Give several reasons why Python is such a great programming language. Explain how Python is related to flowcharts. (students mak
    9·1 answer
  • Beverly is creating a website for her new clothing company. Aside from including photographs, how can she use the index page to
    8·2 answers
  • What does the Attack Time slider let you set?
    12·1 answer
  • Who wants to join my go.ogle classroom?
    15·2 answers
  • In an etl process, data is loaded into a final target database such as:______
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!