Question

JAVA / I KNOW THERE IS MORE THAN ONE QUESTION BUT THEY ARE SO EASY FO...

JAVA / I KNOW THERE IS MORE THAN ONE QUESTION BUT THEY ARE SO EASY FO YOU I NEED YOUR HELP PLEASE HELP ME. I WILL GIVE UPVOTE AND GOOD COMMENT THANK YOU SO MUCH !!!

QUESTION 1

  1. What is the output after the code executes? Assume there are no syntax errors and the code will compile.

    int x = 10;
    do
    {
    System.out.println ( x );
    x -= 3;
    }
    while (x > 0);

    A.


    10
    7
    4
    1

    B.


    1
    7
    4
    10

    C.

    10, 7, 4, 1

    D.

    1, 4, 7, 10

QUESTION 2

  1. What is the value of x after the loop is done executing? Assume there are no syntax errors and the code will compile.

    int x = 10;
    do
    {
    System.out.println ( x );
    x -= 3;
    }
    while (x > 0);

    A.

    10

    B.

    1

    C.

    0

    D.

    -1

    E.

    -2

QUESTION 3

  1. What is the output of the program segment? Assume there are no syntax errors and the code will compile.

    int i = 1;
    int n = 0;
    do
    {
    System.out.print( i );
    i++;
    }
    while (i <= n);

    A.

    0

    B.

    1

    C.

    -1

    D.

    2

QUESTION 4

  1. What are the values of i and n after execution? Assume there are no syntax errors and the code will compile.

    int i = 1;
    int n = 0;
    do
    {
    System.out.print( i );
    i++;
    }
    while (i <= n);

    A.

    i = 1 and n = 0 when done.

    B.

    i = 0 and n = 1 when done.

    C.

    i = 2 and n = 0 when done.

    D.

    i = -1 and n = 2 when done.

QUESTION 5

  1. What is the output of the following program segment?

    Assume there are no syntax errors and the code will compile.

    int x = 4;
    do
    {
    System.out.println ( x );
    x += 2;
    }
    while (x > 0);

    A.


    4
    6
    8
    10

    B.

    0, 0, 0, 0

    C.

    Will not loop at all.

    D.

    Infinite loop.

QUESTION 6

  1. What is the value of x when the loop is done? Assume there are no syntax errors and the code will compile.

    int x = 4;
    do
    {
    System.out.println ( x );
    x += 2;
    }
    while (x > 0);

    A.

    x will stay at 4.

    B.

    The loop is infinite so x will keep getting larger.

    C.

    x will be less than zero.

    D.

    x will be zero.

QUESTION 7

  1. What is the output of the following program segment? Assume there are no syntax errors and the code will compile.

    int i;
    int n = 0;
    for (i = 1; i <= n; i++)
      System.out.print (i);

    A.

    There is no output.

    B.

    Output: 1

    C.

    Output: 0

    D.

    Output: -1

Homework Answers

Answer #1

Question -1 -->

Answer is A

here, x = 10 and while loop continues till the value of x is greater than 0

so, first it will print 10 on the screen, and then the line is changed,

and then, x- = 3 ==> x = x - 3 ==> x = 10 - 3 = > x =7

so, loop will continue,

now, it will print 7 on the screen and then the line will be changed,

and then x-3 ==> x = 4.

so, loop will continue,

now, it will print 4 on the screen and then the line will be changed,

and then x-3 ==> x = 1.

so, loop will continue,

now, it will print 1 on the screen and then the line will be changed,

and then x-3 ==> x = -2

now loop will be terminated.

And so output will be -->

10

7

4

1

So, answer is A..

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
I wrote the following java code with the eclipse ide, which is supposed to report the...
I wrote the following java code with the eclipse ide, which is supposed to report the number of guesses it took to guess the right number between one and five. Can some repost the corrected code where the variable "guess" is incremented such that the correct number of guesses is displayed? please test run the code, not just look at it in case there are other bugs that exist. import java.util.*; public class GuessingGame {    public static final int...
In Java programming language 11.Create the code for a for loop to print the numbers 1  through...
In Java programming language 11.Create the code for a for loop to print the numbers 1  through 5 inclusive vertically so the output is 1 2 3 4 5 11b What is the output of the following               OUTPUT int i=3; while(int i >0) { System.out.println(i); i--; } 11c What is the output of the following               OUTPUT for(int i=3;i<10;i++) System.out.println(3*i); 11d Create the line of code to print the numbers 10 through 1 decreasing by 1 each time 11e Create the line of code...
JAVA - take each for loop and rewrite as a while statement a) int result =...
JAVA - take each for loop and rewrite as a while statement a) int result = 0; for (int i = 1; i <= 10; i++) { result = result + i;} System.out.println(result); b) int result = 1; for (int i = 1; i <= 10; i++) {result = i - result;} System.out.println(result); c) int result = 1; for (int i = 5; i > 0; i--) {result = result * i;} System.out.println(result); d) int result = 1; for (int...
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...
(java) a. The following code has compilation AND logic errors. Rewrite the code (using the while...
(java) a. The following code has compilation AND logic errors. Rewrite the code (using the while loop) so it will compile correctly and print all the even numbers from 0 to 10 on one line separated by a space: int j = 0; while j > 10 ; j + 2; System.println(j, “ “); b.You want to print the values of integers a and b to an external file “test123.txt”, assigned to the PrintWriter variable output. Correct the following statements:...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class...
1) Consider the following Java program, which one of the following best describes "setFlavor"? public class Food {     static int count;     private String flavor = "sweet";     Food() { count++; }     void setFlavor(String s) { flavor = s; }     String getFlavor() { return flavor; }     static public void main(String[] args) {         Food pepper = new Food();         System.out.println(pepper.getFlavor());     } } a. a class variable b. a constructor c. a local object variable d....
BASIC c++ question Please do not try to fix this, I just have a question regarding...
BASIC c++ question Please do not try to fix this, I just have a question regarding the function of this code. I understand this is an infinite loop, however, why is it that when I enter '0', it continues to ask the user for an input, but when I enter a letter, it continues infinitiy. And when it does infinitely loop, why is it that it continues to add 1 to each number? Doesn't the loop go through each line...
What is wrong with the following function: public static void funMethod() { int i=100; while (i...
What is wrong with the following function: public static void funMethod() { int i=100; while (i < 10) { System.out.println("i="+i); i++; } } Select one: a. loop control variable not declared b. loop control variable is never updated c. loop control variable not initialized d. loop control variable never resolves to true e. nothing is wrong with this code. What is wrong with the following function: public static void funMethod() { int i=1; while (i < 10) { System.out.println("i="+i); i++;...
Consider the following Java program : public static void main (string args [ ]) { int...
Consider the following Java program : public static void main (string args [ ]) { int result, x ; x = 1 ; result = 0; while (x < = 10) { if (x%2 == 0) result + = x ; + + x ; } System.out.println(result) ; } } Which of the following will be the output of the above program? A. 35 B. 30 C. 45 D. 35 2. public static void main(String args[]) { int i =...
question : Take the recursive Java program Levenshtein.java and convert it to the equivalent C program....
question : Take the recursive Java program Levenshtein.java and convert it to the equivalent C program. Tip: You have explicit permission to copy/paste the main method for this question, replacing instances of System.out.println with printf, where appropriate. You can get the assert function from assert.h. Try running the Java program on the CS macOS machines. You can compile and run the program following the instructions discussed in class. Assertions are disabled by default. You can enable assertions by running java...