Question
Please answer both questions thank you.
Question 52 (1 point) What is the output of the code snippet given below? String s = abcde; int i = 1; while (i < 5) { Syst
Question 50 (1 point) How many times will the output line be printed in the following code snippet? Please enter your answer
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Q1. OUTPUT: OF THE CODE..

import java.util.*;

import java.lang.*;

import java.io.*;

class Main

{

public static void main (String[] args) throws java.lang.Exception

{

String s="abcde";

/*given the string here "abcde" since index starts from

0 to 4 to denote 5 Characters in the string we have....

and substring(k,l) prints the string from the given string from

string starting at index k and upto l-1.. as we have seen it..

so in each substring(i,i+1 ) will print substring from i to i i.each

1 Character the Character at index i so

in case of

1st iteration it will print s[1]=b

second iteration s[2]=c

third iteration s[3]=d

s[4]=e......so on..

and loop stops when i=5.. so

output: bcde

you can see it in the output section below...

*/

int i=1;

while(i<5)

{

System.out.print(s.substring(i,i+1));

i++;

}

}

}



OUTPUT;

bcde

SINCE SUBSTRING(I,I+1) STARTS AT INDEX I AND UPTO I+1-1 SO ONE CHARACTER AT A TIME OF GIVEN INDEX..

SO OUTPUT:

AS ABOVE..

Q2. WE PRINT THE ANSWER BELOW CODE.


import java.util.*;

import java.lang.*;

import java.io.*;

class Main

{

public static void main (String[] args) throws java.lang.Exception

{

int count=0;

   

  /*since we have nested loops here in this code

so for the first for loop we have it running from i =0 to i=2 ..[0 1 2 ]

so it runs for 3 times .. %outer loop .

now for each outer loop we have an inner loop .. runiiing from j =1 to 3..[1,2, 3..]

so 3 times so we have the nested loop running over 3*3 times.

so 9 times

answer =9 since println function prints line each times ..

so we have counted also the output here below..

and count =9 .. you can well see in the output:

*/

    

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

{

for(int j=1; j<4; j++)

{

System.out.println(""+ i+" "+j);

count++;

}

        

}

System.out.println("answer = "+count);

}

}

OUTPUT;

0 1

0 2

0 3

1 1

1 2

1 3

2 1

2 2

2 3

answer = 9

SO THE NO.. OF TIMES LINES WILL BE PRINTED IS =9..

NOTE: IN CASE OF ANY QUERY PLZ ASK IN COMENT

THANK YOU


Add a comment
Know the answer?
Add Answer to:
Please answer both questions thank you. Question 52 (1 point) What is the output of the...
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
  • Question 36 (1 point) What is the output of the code snippet given below? String s...

    Question 36 (1 point) What is the output of the code snippet given below? String s = "magnificent"; int i = 1; do { if (i > 2) System.out.print(s.substring (1, i)); } i++; } while (i < 5);

  • Please answer both questions. Thanks Question 26 (1 point) What is the output generated by the...

    Please answer both questions. Thanks Question 26 (1 point) What is the output generated by the code segment below, assuming that data is a Scanner object used to read the following text: As the world turns. data.useDelimiter(" "); int count = 0; while (data.hasNext()) { char input data.next().charAt(0); if (! Character.isLetter (input)) { count++; System.out.println (count); A/ Question 27 (1 point) Assuming that the user provides 114 as input, what is the output of the following code snippet? Please make...

  • Please answer both questions thank you. Question 49 (1 point) What is wrong with the following...

    Please answer both questions thank you. Question 49 (1 point) What is wrong with the following code snippet? for (int i 1; i <= 5; i++) { int squared = i + i; System.out.println(i + IT "! squared = + squared); } System.out.println("Last square = " + squared); calculation error variable scope error O nothing incorrect use of for loop Question 47 (1 point) What are the values of num1 and num2 and result after the execution of mystery (num1,...

  • Please answer both questions thank you. Assuming that a user enters 8, 15, and 11 as...

    Please answer both questions thank you. Assuming that a user enters 8, 15, and 11 as input values one after another, separated by spaces, what is the output of the following code snippet? int num1 = 0; int num2 = 0; int num3 = 0; Scanner in = new Scanner (System.in); System.out.print("Enter a number: "); numl - in.nextInt(); System.out.print("Enter a number: "); num2 = in.nextInt(); System.out.print("Enter a number: "); num3 = in.nextInt(); if (numl > num2) if (numl > num3)...

  • Please answer both questions. Thanks Question 24 (1 point) What value would be returned if the...

    Please answer both questions. Thanks Question 24 (1 point) What value would be returned if the method mystery were called and passed the array values (1, 15, 37, 12) as its parameter? public static int mystery (int[] list) int x = 0; for (int i = 1; i < list.length; i++) { int y = list[i] - list [0]; if (y > x) x = Y } } return x; 29 35 1 36 Question 25 (1 point) What is...

  • I am in an entry-level Java class and need assistance solving questions 20-25 for a homework...

    I am in an entry-level Java class and need assistance solving questions 20-25 for a homework assignment. Any help is appreciated. Thank you. Q20 Read the code and answer the question 6 Points Read each of the following code snippets and determine if they are equivalent. I.e. they produce the same output. Q20.1 Are these snippets equivalent? 2 Points Snippet 1: int i=0; while (i<10) System.cut.print(i); i++; 1 Snippet 2: for(int i-0; i<10; i++) System.out.print(i); } Yes O No Q20.2...

  • (a)How many times does the code snippet given below display "Hello"? int x = 1; while...

    (a)How many times does the code snippet given below display "Hello"? int x = 1; while (x != 15) {    System.out.println ("Hello");    x++; } (b)What is the output of the following code fragment? int i = 1; int sum = 0; while (i <= 5) {    sum = sum + i;    i++; } System.out.println("The value of sum is " + sum); Quie 2 What is the output of the following snipped code? public class Test {...

  • Question 6 (1 point) What is the output of the following code snippet? Please ensure your...

    Question 6 (1 point) What is the output of the following code snippet? Please ensure your answe. spaced according to the program code output. public static void main(String[] args) int channel = assignChannel (2); System.out.println("Channel: " + channel); ) public static int assignChannel(int channel) return channel + 3; > A/

  • Please answer both questions thank you. Question 5 (1 point) Consider a file called input.txt that...

    Please answer both questions thank you. Question 5 (1 point) Consider a file called input.txt that has the following 4 lines: Trace the program I when it is 89 lines 78.5 is average. Isn't it? What would be the value of count after the following code snippet executes? Scanner in = new Scanner (new File("input.txt")); int count = 0; while (in.hasNext() ( String value = in.next()); count++; System.out.println(count); A/ Question 7 (1 point) Assume that n is 8 and k...

  • Question 15 (1 point) What does this program print? Please make sure your spacing is exact....

    Question 15 (1 point) What does this program print? Please make sure your spacing is exact. public class Test { System.out.print("39 + 3"); System.out.println(39 + 3); } 1 A/ Question 5 (1 point) Consider a file called input.txt that has the following 4 lines: Trace the program when it is 89 lines 78.5 is average. Isn't it? What would be the value of count after the following code snippet executes? Scanner in = new Scanner (new File("input.txt")); int count 0;...

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