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 = n-1; j >= 0; j--)
System.out.print(x[j]);
}
}
c.
class Driver {
public static void main(String[] args) {
int a = 3;
int b = 1;
for (int c = 1; c < 6; c++) {
b = 1;
while (b < c) {
a = a + 2;
b = b + a;
}
System.out.print(a);
}
System.out.print(b);
}
}
d.
class Driver {
public static void main(String[] args) {
int a = foo(2);
int b = bar(a);
System.out.print(b);
}
static int foo(int a) {
a = bar(a + 5);
System.out.print(a);
return a;
}
static int bar(int a) {
System.out.print(a);
return a + 6;
}
}please evaluate the following code. this is JAVA a. class Car { public int i =...
What is the Java output? Part One: class Driver { public static void main(String[] args) { int a = 5; int b = 3; if (a < b || a * 2 < b) System.out.print(a - b); System.out.print(b + a); } } Part Two: class Driver { public static void main(String[] args) { int a = 5; int b = 8; if (a < b) if (a * 2 < b) System.out.print("foo"); else System.out.print("bar"); else System.out.print("buz"); } }
I need a java flowchart for the following code: import java.util.*; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); System.out.print("Enter the input size: "); int n=sc.nextInt(); int arr[]=new int[n]; System.out.print("Enter the sequence: "); for(int i=0;i<n;i++) arr[i]=sc.nextInt(); if(isConsecutiveFour(arr)) { System.out.print("yes the array contain consecutive number:"); for(int i=0;i<n;i++) System.out.print(arr[i]+" "); ...
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; } }
I must implement a class to calculate n-th row of Pascal's Triangle (in Java). I need to create a static method that takes an argument "n" and returns the n'th line of pascal's triangle. the main method, which will call the class, is already done and the class is set up. Please build this without modifying the main method and without modifying exactly what the static method returns. public class Main { public static void main(String[] args) { int n...
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...
import java.util.Scanner; public class Chpt7_Project { public static void bubbleSort(int[] list) { int temp; for (int i = list.length - 1; i > 0; i--) { for (int j = 0; j < i; j++) { if (list[j] > list[j + 1]) { temp = list[j]; list[j] = list[j + 1]; list[j + 1] = temp; } } } ...
1) Consider the following Java program: 1 public class HelloWorld { 2 // My first program! 3 public static void main(String[] args) { 4 System.out.println("Hello, World!"); 5 } 6 } What is on line 1? a. a variable declaration b. a statement c. a method (subroutine) definition d. a comment e. a class definition 2) Which one of the following does NOT describe an array? a. It can be used in a for-each loop. b. It has a numbered sequence...
4. class Person { 2} public void printValue(int i, int j) {/*…*/ } 3} public void printValue(int i){/*...*/ } 4} } 5) public class Teacher extends Person { 6} public void printValue() {/*...*/ } 7} public void printValue(int i) {/*...*/} 8} public static void main(String args[]){ 9} Person t = new Teacher(); 10} t.printValue(10); 11} } 12} } Which method will the statement on line 10 call? A. on line 2 B. on line 3 C. on line 6 D....
public class ConsCell
{
private int head;
private ConsCell tail;
public ConsCell(int h, ConsCell t)
{
head = h;
tail = t;
}
public int getHead()
{
return head;
}
public ConsCell getTail()
{
return tail;
}
public void setTail(ConsCell t)
{
tail = t;
}
}
public class IntList
{
private ConsCell start;
public IntList (ConsCell s)
{
start = s;
}
public IntList cons(int h)
{
return new IntList(new ConsCell(h, start));
}
public int length()
{
int len...
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