The following individual two programs are using while loop in order to print a specific output:
The outputs of the first program are:
10
9
8
5
4
The outputs of the second program are:
123456789
Using the Table 3.1 below, allocate the error(s) of each line of two programs and type of error:
The first program:
The second program:
Table 3.1
|
Line Number |
Error |
Type of error(logical error or Syntax error) |
|
1 |
Miss word class |
Syntax error |
|
2 |
no |
no |
|
3 |
||
|
4 |
||
|
5 |
||
|
6 |
||
|
7 |
||
|
8 |
||
|
9 |
||
|
10 |
||
|
11 |
||
|
12 |
||
|
13 |
||
|
14 |
||
|
15 |
||
|
16 |
||
|
17 |
||
|
18 |
||
|
19 |
||
|
20 |
Program:

public class Main
{
public static void main(String args[]){
int i=10;
while(i>=4){
if(i!=6 && i!=7)// Here checking the i value equals to 6 or
7
{
System.out.println(i);// Here this statement is printed if above
condition is True
}
i--;// Here decrementing the value of i
}
}
}
Output:

Program:
public class Main
{
public static void main(String args[]){
int i=1;
while(i<10){ // Here checking the i value equals to 10
System.out.print(i);// Here this statement is printed if above
condition is True
i++;// Here incrementing the value of i by 1
}
}
}
Output:

| Line Number | Error | Type of error(logical error or Syntax error) |
| 1 | Miss word class | Syntax error |
| 2 | no | no |
| 3 | no | no |
| 4 | ';' expected | Syntax error |
| 5 | no | no |
| 6 | no | no |
| 7 | no | no |
| 8 | no | no |
| 9 | no | no |
| 10 | no | no |
The following individual two programs are using while loop in order to print a specific output:...
The following individual two programs are using while loop in order to print a specific output: The outputs of the first program are: 10 9 8 5 4 The outputs of the second program are: 123456789 Using the Table 3.1 below, allocate the error(s) of each line of two programs and type of error: The first program: public Main { public static void main(String args[]){ int i=10 while(i>4){ System.out.print(i); i++; } } } The second program: public class Main {...
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...
Which of the following are valid array declarations? a. int[] array- new int[10]; b. double [array double[10]; c. charl charArray "Computer Science"; None of the above Analyze the following code: class Test public static void main(Stringl] args) System.out.println(xMethod(10); public static int xMethod(int n) System.out.println("int"); return n; public static long xMethod(long n) System.out.,println("long"); return n The program displays int followed by 10 The program displays long followed by 10. The program does not compile. None of the above. tions 3-4 are...
What is the output of the following codes? Line1: public class ArrayLength { Line2: public static void main(String args[]) { Line 3: int a[] = {45, 44, 39, 48, 37); Line 4: System.out.print(a.length()); Line5: Line 6: } w Compiling error Oo 05 04
Help with a question in Java: What is the output from the following program? public class Methods2 { public static void main(String[] args) { for (int i = 0; i < 3; i++) { for (int j = 0; j <= i; j++){ System.out.print(fun(i, j) + "\t"); } System.out.println(); } } static long fun(int n, int k) { long p = 1; while (k > 0){ p *= n; } return p; } }
Recursion Tree Goal: Predict the output of a recursive method call using a recursion tree. Draw the recursion tree of the following source code, showing all method calls and outputs: public class Main { public static void main(String[] args) { f(3, 4); } public static void f(int x, int y) { if(x + y > 1) { f(x - 2, y - 1); System.out.print(x + " "); f(y, x - 2); System.out.print(2 * x + y + " "); }...
output
What is the output of the following: class Access public int x; private int y public void cal(int x, int y) { this.x = x + 1; this.y = y; } public void print() { System.out.print(""+y); } } class AccessSpecifier { public static void main(String args[]) { Access obj = new Access(); obj.cal(2, 3); System.out.print(obj.x); obj.print(); } } 33 Compilation error 23 None of the available choices Runtime error
I need a java program that prints the following: 1* 2** 3*** 4**** 5***** 6****** 7******* 8******** 9********* This is what I have so far, but I cannot figure out how to fix it. public class HelloWorld{ public static void main(String []args){ System.out.println("Pattern Two"); for (int line=1; line<10; line++){ System.out.println(); for (int j=1; j System.out.print(line); for (int i=1; i System.out.print("*"); } } } } }
Complete the do-while loop to output 0 to countLimit. Assume the user will only input a positive number. import java.util.Scanner; public class CountToLimit { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); int countLimit = 0; int printVal = 0; // Get user input countLimit = scnr.nextInt(); printVal = 0; do { System.out.print(printVal + " "); printVal = printVal + 1; } while ( /* Your solution goes here */ ); System.out.println(""); return; } }
please evaluate the following code. this is JAVA a. class Car { public int i = 3; public Car(int i) { this.i = i; } } ... Car x = new Car(7), y = new Car(5); x = y; y.i = 9; System.out.println(x.i); b. class Driver { public static void main(String[] args) { int[] x = {5, 2, 3, 6, 5}; int n = x.length; for (int j = n-2; j > 0; j--) x[j] = x[j-1]; for (int j...