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
drek231 [11]
3 years ago
14

What is the output of the second println statement in the main method? public class Foo { int i; static int s; public static voi

d main(String[] args) { Foo f1 = new Foo(); System.out.println("f1.i is " + f1.i + " f1.s is " + f1.s); Foo f2 = new Foo(); System.out.println("f2.i is " + f2.i + " f2.s is " + f2.s); Foo f3 = new Foo(); System.out.println("f3.i is " + f3.i + " f3.s is " + f3.s); } public Foo() { i++; s++;
Computers and Technology
1 answer:
never [62]3 years ago
6 0

Answer:

The second print statement will print:

f2.i is 1 f2.s is 2

Explanation:

Initially when the execution start. i and s are both 0. i declared as a variable while s is a static variable which value stays once it is re-defined.

When f1 call i and s; their value is both 1 based on the increment statement in the constructor.

For the second print statement:

When f2 call i; it is re-initialized to 1. When f2 call s; it has initial value of 1 and is incremented to 2 which is printed. s hold the initial value of 1 because of the static keyword.

You might be interested in
A network technician has created a network consisting of an external internet connection, a DMZ,
Elden [556K]

Answer:

B.The admin private network allowing only admin access.

Explanation:

When the network technician created the network that consists of an external internet connection ,an internal private network,an administrative network and a DMZ.All the routers and the switches should be configured so that they can accept SSH connections from the admin private network that allows only admin access.

6 0
4 years ago
Write a function ngrams(n, tokens) that produces a list of all n-grams of the specified size from the input token list. Each n-g
ki77a [65]

Answer:

Explanation:

Assuming input is a string contains space separated words,

like x = "a b c d" we can use the following function

def ngrams(input, n):

input = input.split(' ')

output = []

for i in range(len(input)-n+1):

output.append(input[i:i+n])

return output

ngrams('a b c d', 2) # [['a', 'b'], ['b', 'c'], ['c', 'd']]

If you want those joined back into strings, you might call something like:

[' '.join(x) for x in ngrams('a b c d', 2)] # ['a b', 'b c', 'c d']

Lastly, that doesn't summarize things into totals, so if your input was 'a a a a', you need to count them up into a dict:

for g in (' '.join(x) for x in ngrams(input, 2)):

grams.setdefault(g, 0)

grams[g] += 1

Putting all together

def ngrams(input, n):

input = input.split(' ')

output = {}

for i in range(len(input)-n+1):

g = ' '.join(input[i:i+n])

output.setdefault(g, 0)

output[g] += 1

return output

ngrams('a a a a', 2) # {'a a': 3}

6 0
4 years ago
Human services organizations seek to make changes and help people in need to improve their .
bixtya [17]

Answer:

quality of life

Explanation:

7 0
3 years ago
Typically, the first item in defining a function is _____. (Points : 4)
sveticcg [70]

Answer: Naming the function

Explanation:

 The first item for defining the function is the naming of the function. In the function, the first line is known as header and rest of the function is known as body of the function.

The function name is the first step while defining the proper function as we can define the actual function name on which the program are rest based.

We can define a function from which the each value from the set of the components are basically associated with the second component in that particular function.

 

8 0
3 years ago
2. The factorial of a positive integer n is the product of the integers from 1 to n. You can express the factorial of a positive
Molodets [167]

Answer:

import java.io.*;

import java.util.Scanner;//importing the scanner.

class Factorial {

public static void main (String[] args) {

    Scanner fact=new Scanner(System.in);//creating a scanner object for taking the input.

    int t,n;//t for number of times the user want to calculate the factorial and n for factorial.

    System.out.println("How many times you want to calculate the factorial");

    t=fact.nextInt();//taking input of t.

    while(t>0)

    {

        int f=1;//f for calculating the variable.

        n=fact.nextInt();//taking input of n .

        if(n>10||n<1)//if n is out of range then again taking input.

        {

           while(n>10 || n<1)

                {

                        System.out.println("Please Enter the Valid Input");

                 n=fact.nextInt();

                }

               for(int i=1;i<=n;i++)//calculating the factorial.

               {

                   f*=i;

               }

               System.out.println("The factorial is: "+ f);

        }

        else // if n is in  range then definitely calculating the factorial.

        {

             for(int i=1;i<=n;i++)// calculating the factorial.

               {

                   f*=i;

               }

               System.out.println("The factorial is: "+ f);

        }

    }

}

}

Output:-

How many times you want to calculate the factorial

2

-5

Please Enter the Valid Input

4

The factorial is: 24

5

The factorial is: 120

Explanation:

The above written code is for calculating the factorial of an integer the number of times user want to calculate the factorial.The code wants user to enter again until the value entered by the user is in range.If the value is in range then it definitely calculates the factorial.

6 0
3 years ago
Other questions:
  • Is it possible to increase watch hours for a channel by making a playlist out of your videos for people to watch? Will it boost
    13·1 answer
  • . What is the output of this code sequence?
    8·1 answer
  • A ___________ lists all possible packet switches and gives a next hop for each.
    12·1 answer
  • Markup is best defined as
    11·1 answer
  • WHAT DOES THE WORD MONOCHROME MEAN?
    11·1 answer
  • True and False: High-speed Internet service is free form of information technology that these businesses can utilize.
    13·1 answer
  • This type of software works with end users, application software, and computer hardware to handle the majority of technical deta
    12·1 answer
  • Write an algorithm that receives a number from the user (you can store the number in a variable called N). Then the algorithm sh
    8·1 answer
  • Write a Python Program that:
    9·1 answer
  • PLZ HELP ME!!
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!