Question

What is "missing part" in the piece of code below to produce the following output 012345...

What is "missing part" in the piece of code below to produce the following output

012345
12345
2345
345
45
5

String base = "012345";

int count = 0;
while (count <= 5)
{
  String tmp = ______________;
System.out.println(tmp);
count++;   
}

a) base.substring(count,6)

b) base.substring(1,count+1)

c) base.substring(0, count)

D)base.substring(count+1)

e)  base.substring(count)

Homework Answers

Answer #1

Given code:

public class Missing {
   public static void main(String[] args) {
       String base = "012345";
       int count = 0;
       while(count <= 5) {
           String tmp = ------------------------;
           System.out.println(tmp);
           count++;
       }
   }
}
Options:

  • a) base.substring(count,6)

  • b) base.substring(1,count+1)

  • c) base.substring(0, count)

  • D)base.substring(count+1)

  • e)  base.substring(count)

Answer: Option (a) and (e) gives the same result.

CODE:

public class Missing {
   public static void main(String[] args) {
       String base = "012345";
       int count = 0;
       while(count <= 5) {
           String tmp = base.substring(count,6);
           System.out.println(tmp);
           count++;
       }
   }
}

SCREENSHOT OF THE CODE:

OUTPUT:

CODE:

public class Missing {
   public static void main(String[] args) {
       String base = "012345";
       int count = 0;
       while(count <= 5) {
           String tmp = base.substring(count);
           System.out.println(tmp);
           count++;
       }
   }
}

SCREENSHOT OF THE CODE:

OUTPUT:

Thank you.

Know the answer?
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
Similar Questions
What is the condition in "if" statement in the piece of code below to produce the...
What is the condition in "if" statement in the piece of code below to produce the following output 4 9 14 19 end int count = 1; while (count <= 5) { if (_____) System.out.print(5*count - 1 + " "); else System.out.print("end"); count++; } count != 5 count = 5 count < 5 !(count == 5) count > 5
For the following piece of Java code: a) State which object creation mechanism is being used...
For the following piece of Java code: a) State which object creation mechanism is being used b) Explain how you determined which object creation mechanism is being used c) Complete the missing portions of the code (indicated by underscores) ____________________ part1 { public void function1(String someInput); public double function2(); public int function3(int thisVal, int thatVal); } public ____________________part2 ____________________ { double aNumber; public void function1(String someInput) { System.out.println(someInput); } public double function2() { aNumber = 6.0; return aNumber; } public...
Re-write following if-else-if statements as Switch statement. Your final code should result in the same output...
Re-write following if-else-if statements as Switch statement. Your final code should result in the same output as the original code below. if (selection == 10) System.out.println("You selected 10."); else if (selection == 20) System.out.println("You selected 20."); else if (selection == 30) System.out.println("You selected 30."); else if (selection == 40) System.out.println("You selected 40."); else System.out.println("Not good with numbers, eh?"); Second question Re-write following while loop into Java statements that use a Do-while loop. Your final code should result in the same...
what output is produced by the following code and explain how it works. public class A...
what output is produced by the following code and explain how it works. public class A { int a = 1; int b = 2; public int getSum(int a, int b) {     this.a+=a;     this.b+=b;     return this.a + this.b; } } public class B extends A { int a = 3; int b = 4; public int getSum(int a, int b) {     this.b=a;     super.b=b+b;     return super.a+this.b; } } public class q2 { public static void...
1) Consider the following Java program. Which statement updates the appearance of a button? import java.awt.event.*;...
1) Consider the following Java program. Which statement updates the appearance of a button? import java.awt.event.*; import javax.swing.*; public class Clicker extends JFrame implements ActionListener {     int count;     JButton button;     Clicker() {         super("Click Me");         button = new JButton(String.valueOf(count));         add(button);         button.addActionListener(this);         setSize(200,100);         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         setVisible(true);     }     public void actionPerformed(ActionEvent e) {         count++;         button.setText(String.valueOf(count));     }     public static void main(String[] args) { new Clicker(); } } a. add(button);...
This is the java code that I have, but i cannot get the output that I...
This is the java code that I have, but i cannot get the output that I want out of it. i want my output to print the full String Form i stead of just the first letter, and and also print what character is at the specific index instead of leaving it empty. and at the end for Replaced String i want to print both string form one and two with the replaced letters instead if just printing the first...
3. What will be the value of w after the following section of code executes: int...
3. What will be the value of w after the following section of code executes: int w = 4, q = 3; if (q > 5)       if (w == 7)           w == 3;       else            if (w > 3)               w = 1;            else               w = 0; A.0            B.1              C.2          D.3 4. What will be the value of b after the following section of code executes: int a = 4, b = 0; if (a...
Q1: Re-write following if-else-if statements as Switch statement. Your final code should result in the same...
Q1: Re-write following if-else-if statements as Switch statement. Your final code should result in the same output as the original code below. if (selection == 10) System.out.println("You selected 10."); else if (selection == 20) System.out.println("You selected 20."); else if (selection == 30) System.out.println("You selected 30."); else if (selection == 40) System.out.println("You selected 40."); else System.out.println("Not good with numbers, eh?"); Q2: Re-write following while loop into Java statements that use a Do-while loop. Your final code should result in the same...
Java question, Please answer everything. Thank you Answer the following questions as briefly (but completely) as...
Java question, Please answer everything. Thank you Answer the following questions as briefly (but completely) as possible: What is a checked exception, and what is an unchecked exception? What is NullPointerException? Which of the following statements (if any) will throw an exception? If no exception is thrown, what is the output? 1: System.out.println( 1 / 0 ); 2: System.out.println( 1.0 / 0 ); Point out the problem in the following code. Does the code throw any exceptions? 1: long value...
Select the output for the following set of Code: static void Main(string[] args) { int x...
Select the output for the following set of Code: static void Main(string[] args) { int x = 0; while (x < 20) { while (x < 10) { if (x % 2 == 0) { Console.WriteLine(x); } x++; } } Console.ReadLine(); } Select one: a. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 b. 0 2 4 6 8 10 12 14 16 18 20 c. 0 2...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT