Question

1. What is the output when you run printIn()? public static void main(String[] args) { if...

1. What is the output when you run printIn()?
public static void main(String[] args)
{
if (true) {
int num = 1;
if (num > 0) {
num++;
}
}
int num = 1;
addOne(num);
num = num - 1
System.out.println(num);
}
public void addOne(int num)
{
num = num + 1;
}
2. When creating an array for primitive data types, the default values are:
a. Numeric type
b. Char type
c. Boolean type
d. String type
e. Float type
3. Create an array of 15 float numbers.
4. Syntax of foreach loop with an example.
5. Copy the content of array myarray1 = {1,2,3} into new array myarray2.
6. Complete the highlighted parts in below code:
public static ___ addOneToEach(int[] list) {
int[] result = new int[list.length];

for (int i = 0; i < list.length; i++)
result[i] = ___ + 1;
return result;
}
7. How to calculate the row and column of two-dimensional array.
8. Complete the highlighted code for printing two-dimensional array:
for (int row = 0; row < ____; row++) {
for (int col = 0; col < ____; col++)
9. Complete the following for method definition of passing 2D array:
public static void methodExample(__) {
// Method body
}
10. Answer below:
a. Constructors are invoked using ________ operator when an object is created.
b. They need a void return type. - True or False?
11. Syntax and examples of constructor(with and without parameter).
12. What does a default constructor provide?
13. How do you invoke a method in an object?
14. Difference between a and b:
Circle myCircle1 = new Circle();
Circle myCircle2;
a. myCircle2 = myCircle1;
b. myCircle2 = new Circle();
15. ____________ is shared by all objects of a class and is not tied to a specific instance.
16. What will the output when function updatePi() is called?
class newIde
{
public static final int PI = 3.14159;
public static double updatePi() {
PI = PI * 7;
return PI;
}
}
17. If a data field is private, how will other classes use it?
18. A keyword which is used to refer to the object itself.
19. Complete the highlighted code.
class Circle {
private double radius;
...
public double setRadius(double radius) {
________ = radius;
}
}
20. What will be the output of the following program?
public class Rose {
public Rose(String name) {
System.out.println("Passed Name is :" + name);
}
public static void main(String[] args) {
Rose myRose = new Rose("red");
myRose = new Rose("white");
}
}
21. What will be the output of the following program?
public class Counter {
Static int count = 0;
Counter() {
count++;
}
public static void main(String srt[]) {
Counter c1 = new Counter();
Counter c3 = new Counter();
Counter c2 = new Counter();
System.out.print(c1.count + ", ");
System.out.print(c2.count + ", ");
System.out.print(c3.count);
}
}
a. 1,1,1
b. Compilation or runtime error
c. 3,3,3
d. 1,2,3
22. What will be the output of the following program?
public class NewClass2
{
public static void main(String[] args)
{
int ar[] = {1, 2, 3, 4, 5};
for (int i=0; i<=ar.length; i++)
System.out.println(ar[i]);
}
}
a. 1,2,3,4,5 with runtime error
b. Runtime error
c. 1,2,3,4,5
d. 2,3,4,5

0 0
Add a comment Improve this question Transcribed image text
Answer #1

******************************************************************************************
Please Upvote the answer as it matters to me a lot :)
*****************************************************************************************
As HOMEWORKLIB expert answering guidelines, Experts are supposed to answer only a certain number of questions/sub-parts in a post. Please raise the remaining as a new question as HOMEWORKLIB guidelines.
******************************************************************************************

3. Create an array of 15 float numbers.

float [] a= new float[15];

6. Complete the highlighted parts in below code:
public static [] int addOneToEach(int[] list) {
int[] result = new int[list.length];

for (int i = 0; i < list.length; i++)
result[i] =result[i] + 1;
return result;
}

7)

How to calculate the row and column of the two-dimensional array.

let the array is a

int row = a.length;

int column= a[0].length;

Add a comment
Know the answer?
Add Answer to:
1. What is the output when you run printIn()? public static void main(String[] args) { if...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Draw a flowchart for this program public class InsertionSort {     public static void main(String a[]) {...

    Draw a flowchart for this program public class InsertionSort {     public static void main(String a[]) {         int[] array = {7, 1, 3, 2, 42, 76, 9};         insertionSort(array);     }     public static int[] insertionSort(int[] input) {         int temp;         for (int i = 1; i < input.length; i++) {             for (int j = i; j > 0; j--) {                 if (input[j] < input[j - 1]) {                     temp = input[j];                     input[j] = input[j - 1];                     input[j - 1] = temp;                 }             }             display(input, i);...

  • What is the output of following program: public class Test{ public static void main(String[] args) {...

    What is the output of following program: public class Test{ public static void main(String[] args) { A a = new A(): a method B(): } } class A{ public A(){ System out println("A's constructor is executed"): } public void method(){ System out printin ("methodA is executed"): } public void methodAB(){ System out printin ("As methodAB is executed"): } } class B extends A { private int num = 0: public B (){ super(): System out printin ("B's constructor is executed"):...

  • import java.util.Scanner; public class TriangleMaker {    public static void main(String[] args) {        //...

    import java.util.Scanner; public class TriangleMaker {    public static void main(String[] args) {        // TODO Auto-generated method stub        System.out.println("Welcome to the Triangle Maker! Enter the size of the triangle.");        Scanner keyboard = new Scanner(System.in);    int size = keyboard.nextInt();    for (int i = 1; i <= size; i++)    {    for (int j = 0; j < i; j++)    {    System.out.print("*");    }    System.out.println();    }    for (int...

  • What is the Java output? Part One: class Driver { public static void main(String[] args) {...

    What is the Java output? Part One: class Driver { public static void main(String[] args) { int a = 5; int b = 3; if (a < b || a * 2 < b) System.out.print(a - b); System.out.print(b + a); } } Part Two: class Driver { public static void main(String[] args) { int a = 5; int b = 8; if (a < b) if (a * 2 < b) System.out.print("foo"); else System.out.print("bar"); else System.out.print("buz"); } }

  • import java.util.LinkedList; public class testprintOut { private static LinkedList[] array; public static void main(String[] args) {...

    import java.util.LinkedList; public class testprintOut { private static LinkedList[] array; public static void main(String[] args) { int nelems = 5; array = new LinkedList[nelems]; for (int i = 0; i < nelems; i++) { array[i] = new LinkedList<String>(); } array[0]=["ab"]; System.out.println(array[0]); } } //I want to create array of linked lists so how do I create them and print them out efficiently? //Syntax error on token "=", Expression expected after this token Also, is this how I can put them...

  • what is output public static void main(String args) Scanner keyboard new Scanner(System.in); int u 14; int...

    what is output public static void main(String args) Scanner keyboard new Scanner(System.in); int u 14; int w 0; int x; int y 5; float z = 6.1 System.out.print("Enter y: "); x keyboard.nextint); System.out.println('y'); System.out.println(x); System.out.println(w*3); x- x+(int)z; System.out.println(x); 0 System.out.println(u); System.out.,println(u); System.out.println"x In" + y); System.out.print(y + z); ) liclosing main method 1 liclosing class header

  • What output is produced by the following program? public class MysteryNums public static void main(String[] args)...

    What output is produced by the following program? public class MysteryNums public static void main(String[] args) - int x = 12; int y = x - 3; 3, sentence (y, x + y); . public static void sentence (int numi, int num2) { 4: System.out.println(num1 + " + num2);

  • Project 7-3 Guessing Game import java.util.Scanner; public class GuessNumberApp {    public static void main(String[] args)...

    Project 7-3 Guessing Game import java.util.Scanner; public class GuessNumberApp {    public static void main(String[] args) { displayWelcomeMessage(); // create the Scanner object Scanner sc = new Scanner(System.in); String choice = "y"; while (choice.equalsIgnoreCase("y")) { // generate the random number and invite user to guess it int number = getRandomNumber(); displayPleaseGuessMessage(); // continue until the user guesses the number int guessNumber = 0; int counter = 1; while (guessNumber != number) { // get a valid int from user guessNumber...

  • 10. What prints when the following code is executed? public static void main (String args) "Cattywampus"; for (...

    10. What prints when the following code is executed? public static void main (String args) "Cattywampus"; for (int i-s.length )-1 i> 0 i-2) if (s.charAt (i)a') System.out.print(""); ] else if (s.charAt (i)'t') System.out.print (s.charAt (i-2)) i+ti else System. out. print (s . charAt (İ) ) ; if (i<2) System.out.print ("y"); System.out.println () 10. What prints when the following code is executed? public static void main (String args) "Cattywampus"; for (int i-s.length )-1 i> 0 i-2) if (s.charAt (i)a') System.out.print(""); ]...

  • import java.util.Random; import java.util.ArrayList; /** * */ public class hw5_task8 { public static void main(String[] args)...

    import java.util.Random; import java.util.ArrayList; /** * */ public class hw5_task8 { public static void main(String[] args) { int[] grades = randomIntArr(10); printIntArray("grades", grades); ArrayList<Integer> indexesF_AL = selectIndexes_1(grades); System.out.println(" indexesF_AL: " + indexesF_AL); int[] indexesF_Arr = selectIndexes_2(grades); printIntArray("indexesF_Arr",indexesF_Arr); } public static int[] randomIntArr(int N){ int[] res = new int[N]; Random r = new Random(0); for(int i = 0; i < res.length; i++){ res[i] = r.nextInt(101); // r.nextInt(101) returns an in in range [0, 100] } return res; } public static void...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT