Question

JAVA programming language: What is the output? for (int i = 0; i < 3; i++)...

JAVA programming language:

What is the output?

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

for (int j = 0; j < 8; j++) {

if (j>= 2) {

break:

}

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

}

}

Select one:

a) 00 11 22 00 11 22

b) 00 01 10 11 20 21

c) 012 123 234

d) 000 001 100 110 200 210

Homework Answers

Answer #1

In the given code, the inner loop will iterate only 2 times for
outer loop. Third time break will terminate the loop.

The outer loop will iterate 3 times.


(a) 00 11 22 00 11 22
This option is incorrect as 00 is coming again but in the code the outer loop
only runs in ascending order

(b) 00 01 10 11 20 21
This option is correct as the outer loop prints the first digit and inner loop
prints the second digit of a combo.

0 and 1 from the inner loop will be printed for each 0,1 and 2 of the outer loop.

(c) 012 123 234
This is incorrect as three digits cannot be combined without space in output.

(d) 000 001 100 110 200 210
This is incorrect as three digits cannot be combined without space in output.

Therefore, the correct option is (b) 00 01 10 11 20 21

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
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 Programming Language Currently my code is recording all the nodes it took to find the...
Java Programming Language Currently my code is recording all the nodes it took to find the Longest Path. But i only want it to record the nodes that takes it to the longest path. import java.util.*; import java.awt.Point; class Main {     // M x N matrix     private static final int M = 10;     private static final int N = 10;     static ArrayList<Point> Path = new ArrayList<Point>();     // check if it is possible to go to position (x, y) from     //...
C++ Programming Given int ages={7,12,9,6 }; What will be the output statement: cout<<ages; This will display...
C++ Programming Given int ages={7,12,9,6 }; What will be the output statement: cout<<ages; This will display a compiler error 7,12,9,6 0 A hex value Char course [20]=”Intro to c++” ; what character at course[12] will be: \0 A hex value + A space Given char course [20]={ “Intro to c++”}; the character at course[6] will be: \0 The letter o The letter t A space In the following two dimensional Array table [4][3]= {3,7,0,2,4,9,8,1,3,6,5,4}; What is the value of table...
IN JAVA!! You may be working with a programming language that has arrays, but not nodes....
IN JAVA!! You may be working with a programming language that has arrays, but not nodes. In this case you will need to save your BST in a two dimensional array. In this lab you will write a program to create a BST modelled as a two-dimensional array. The output from your program will be a two-dimensional array.   THEN: practice creating another array-based BST using integers of your choice. Once you have figured out your algorithm you will be able...
The code is in C programming language pls convert it into python. Thanks. Program --> #include...
The code is in C programming language pls convert it into python. Thanks. Program --> #include <stdio.h> #include <stdlib.h> void main() { //declare variables FILE *fileptr; char filename[15]; char charRead; char filedata[200],searchString[50]; int i=0,j=0,countNoOfWord=0,count=0; //enter the filename to be opened printf("Enter the filename to be opened \n"); scanf("%s", filename); /* open the file for reading */ fileptr = fopen(filename, "r"); //check file exit if (fileptr == NULL) { printf("Cannot open file \n"); exit(0); } charRead = fgetc(fileptr); //read the string...
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 extern char **environ;    5 void output(char *a[], char...
1 #include <stdio.h> 2 #include <stdlib.h> 3 4 extern char **environ;    5 void output(char *a[], char *b[]) { 6 int c = atoi(a[0]); 7 for (int i = 0; i < c && b[i]; ++i) { 8 printf("%s", b[i]+2); 9 } 10 } 11 12 void main(int argc, char *argv[]) { 13      14 switch (argc) { 15 case 1: 16 for (int i = 0; environ[i]; ++i) {    17 printf("%s\n", environ[i]); 18 } 19 break; 20 default: 21 output(argv +...
What is the output of the following Java program? public class Food {     static int...
What is the output of the following Java program? public class Food {     static int count;     private String flavor = "sweet";     Food() { count++; }     void setFlavor(String s) { s = flavor; }     String getFlavor() { return flavor; }     static public void main(String[] args) {         Food pepper = new Food();         pepper.setFlavor("spicy");         System.out.println(pepper.getFlavor());     } } Select one: a. sweet b. 1 c. The program does not compile. d. 2 e. spicy...
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....
C Programming I am trying to also print the frequency and the occurrence of an input...
C Programming I am trying to also print the frequency and the occurrence of an input text file. I got the occurrence to but cant get the frequency. Formula for frequency is "Occurrence / total input count", this is the percentage of occurrence. Can someone please help me to get the frequency to work. Code: int freq[26] = {0}; fgets(input1, 10000, (FILE*)MyFile); for(i=0; i< strlen(input); i++) { freq[input[i]-'a']++; count++; } printf("Text count = %d", count); printf("\n"); printf("Frequency of plain text\n");...
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);...