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
Anna [14]
3 years ago
8

Consider the following method:

Computers and Technology
2 answers:
Katen [24]3 years ago
8 0

Answer:

See explaination

Explanation:

public class Main {

public static void main(String[] args) {

//execution starts from here so initializing the try block for erros

try{

Scanner keyboard = new Scanner(System.in);

System.out.print("Please enter a file name: ");

String name = keyboard.next();

//the line below throws file not found exception if the given file name is not found or unable to open

Scanner file = new Scanner(new File(name));

String line = file.nextLine();

int n = file.nextInt();

//the below print line function call throws ParameterNotAllowedException if n is zero

printLine(line, n);

}//all Exceptions potentially thrown

catch(InputMismatchException e){

System.out.println("User input type mismatch\n"+e);

}catch(FileNotFoundException e){

System.out.println("Given file name is wrong or does not match");

}catch(ParameterNotAllowedException e){

System.out.println("The n given to printLine must be more than zero");

}catch(IOException ex){

System.err.println("An IOException was caught!");

}

}

//method from above goes here.

public static void printLine(String line, int numberOfTimes) throws Exception {

if (numberOfTimes <=0)

throw new ParameterNotAllowedException("Error. invalid parameter.",numberOFTimes);

for( int i=0; i<numberOfTimes; i++)

System.out.println(line);

}

}

For the user written custom Exception ParameterNotAllowedException. We need to add an exceptional class.

Which is missing from the given info:

class ParameterNotAllowedException extends Exception

{

public ParameterNotAllowedException(String s,int n)

{

// Call constructor of parent Exception

super(s);

}

}

belka [17]3 years ago
5 0

Answer:

Check the explanation

Explanation:

public class Main {

public static void main(String[] args) {

//execution starts from here so initializing the try block for errors

try{

Scanner keyboard = new Scanner(System.in);

System.out.print("Please enter a file name: ");

String name = keyboard.next();

//the line below throws file not found exception if the given file name is not found or unable to open

Scanner file = new Scanner(new File(name));

String line = file.nextLine();

int n = file.nextInt();

//the below print line function call throws ParameterNotAllowedException if n is zero

printLine(line, n);

}//all Exceptions potentially thrown

catch(InputMismatchException e){

System.out.println("User input type mismatch\n"+e);

}catch(FileNotFoundException e){

System.out.println("Given file name is wrong or does not match");

}catch(ParameterNotAllowedException e){

System.out.println("The n given to printLine must be more than zero");

}catch(IOException ex){

System.err.println("An IOException was caught!");

}

}

//method from above goes here.

public static void printLine(String line, int numberOfTimes) throws Exception {

if (numberOfTimes <=0)

throw new ParameterNotAllowedException("Error. invalid parameter.",numberOFTimes);

for( int i=0; i<numberOfTimes; i++)

System.out.println(line);

}

}

For the user written custom Exception ParameterNotAllowedException. We need to add an exceptional class.

Which is missing from the given info:

class ParameterNotAllowedException extends Exception

{

public ParameterNotAllowedException(String s,int n)

{

// Call constructor of parent Exception

super(s);

}

}

You might be interested in
Which formulas would work to combine cells with first, middle, and last names from columns A through C and row 2 into a new cell
AURORKA [14]

Split? not really sure but i understand a bit of this..

6 0
3 years ago
Read 2 more answers
You have a notebook computer and wish to connect to an IEEE 802.11ac wireless network. The computer does not have a built-in WLA
BARSIC [14]

Answer:

Wireless USB 2.0

Explanation:

USB ports are available in all modern notebook computers. This makes the wireless USB 2.0 adapter a capable option to solve the network issue.

Wireless USB 2.0 can send 480Mbit/s and 110Mbit/s at a 3meters and 10 meters respectively, it frequency ranges from 3.1GHz to 10.6GHz.

In cases where the internal wireless card is faulty or the computer does not come with a wireless chip inside, the Wireless USB 2.0 is the right option for you to be able to connect over a network efficiently.

5 0
3 years ago
Where is the fill handle located
Ronch [10]
The fill handle will appear as a small square in the bottom-right corner of the selected cell(s). Click, hold, and drag the fill handle until all of the cells you want to fill are selected. Release the mouse to fill the selected cells
4 0
2 years ago
An array of integers named parkingTickets has been declared and initialized to the number of parking tickets given out by the ci
Sedaia [141]

Answer:

Following code will store the largest value in array parkingTickets in the variable mostTickets

mostTickets = parkingTickets[0];

for(int k = 0; k<parkingTickets.length; k++)

{

if(parkingTickets[i]>mostTickets)

{

 mostTickets = parkingTickets[i];

}

}

Explanation:

In the above code segment, initially the number of tickets at first index is assumed as largest value of tickets in array.

Then using a for loop each value in the array parkingTickets is compared with the current mostTickets value.

If the compared value in parkingTickets array is larger than the current mostTickets value. Then that value is assigned to mostTickets.

This process is repeated for all elements in array.

Thus after looping through each element of array the largest value in array will get stored in mostTickets variable.  

6 0
3 years ago
Read one positive integer n. Then create an n X n two-dimensional array and write the code that stores integers from 1 to n2 as
marysya [2.9K]

Answer:

The program in Java is as follows:

import java.util.*;

public class Main{

public static void main(String[] args) {

    int n;

    Scanner input = new Scanner(System.in);

 System.out.print("Size of array: ");

 n = input.nextInt();

 int count = 1;

 int[][] arr = new int[n][n];

 for(int i = 0; i<n;i++){

     for(int j = 0; j<n;j++){

         arr[i][j] = count;

         count++;      }  }

 for(int i = 0; i<n;i++){

     for(int j = 0; j<n; j++){

         System.out.printf(arr[i][j]+" ");      }

     System.out.println();  } }}

Explanation:

This declares the size of the array

    int n;

    Scanner input = new Scanner(System.in);

This prompts the user for size of array

 System.out.print("Size of array: ");

This gets input for size of array

 n = input.nextInt();

This initializes the array element to 1

 int count = 1;

This creates a 2d array

 int[][] arr = new int[n][n];

This iterates through the rows

 for(int i = 0; i<n;i++){

This iterates through the columns

     for(int j = 0; j<n;j++){

This populates the array

         arr[i][j] = count;

         count++;      }  }

The following nested loop prints the array elements

 for(int i = 0; i<n;i++){

     for(int j = 0; j<n; j++){

         System.out.printf(arr[i][j]+" ");      }

     System.out.println();  } }}

8 0
2 years ago
Other questions:
  • Which access control principle specifies that no unnecessary access to data exists by regulating members so they can perform onl
    11·1 answer
  • Jawana has been working on a paper for her Anatomy class for weeks. One day her little brother was on her computer and accidenta
    14·1 answer
  • An extranet is like an intranet except that it allows company employees access to corporate Web sites from the ______
    13·1 answer
  • What is the full form of icimod?
    6·1 answer
  • To save a presentation, tap or click the save button on the Blank
    8·1 answer
  • Ryan is looking to buy a new HDTV set. He knows from friends that LCD set screens reflect less light than plasma set screens, bu
    10·1 answer
  • I need to calculate the % of Grand Total on Microsoft Excel, but can't for the life of me remember how to do that. Help would be
    8·1 answer
  • Where can a client identify the instant deposit options for their QuickBooks Payments account?
    5·1 answer
  • A friend wants to design an app but has never done so before and isn't sure how to begin. What would you suggest they do first?
    7·1 answer
  • Would it be feasible to combine fixed length field and variable length field format in single disk
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!