Output for VIII
3 4 3
7 4 3 20
3 4 20
Explanation:
public class Tester {
public static void main(String[] args){
int x=3, y=4;
int[] num = {1,2,3,4};
//Printing x, y, array 3rd element with spaces in between
System.out.println(x+" "+y+" "+num[2]);
//This method doesn't return anything, so next output is same as previous one
tryit(y,x,num);
//Printing x, y, array 3rd element with spaces in between
System.out.println(x+" "+y+" "+num[2]);
}
public static void tryit(int a, int b, int[] c) {
// TODO Auto-generated method stub
int x;
x=a+b;
c[2]=20;
System.out.println(x+" "+a+" "+b+" "+c[2]);
}
}
//End of Tester.java class
Program for XI:
import java.util.Arrays;
public class Tester {
public static void main(String[] args){
int[] num = {1,2,-3,-4};
//Printing array before calling the method
System.out.println(Arrays.toString(num));
//This method doesn't return anything, so next output is same as previous one
int sum = negative(num);
//Printing the sum
System.out.println("Negative sum = "+sum);
}
public static int negative(int[] num) {
// TODO Auto-generated method stub
int total=0;
//iterating over array
for (int i=0; i<num.length; i++){
//selecting only negative numbers
if(num[i]<0){
total = total+num[i];
}
}
//return negative sum
return total;
}
}
//End of Tester.java class
Output:
[1, 2, -3, -4]
Negative sum = -7
X. (10 points) In the box provided show the output for this program segment public static...
What is the output of following program: public class Test{ public static void main(String[] args) { A a = new A(): a method B(): } } class A{ public A(){ System out println("A's constructor is executed"): } public void method(){ System out printin ("methodA is executed"): } public void methodAB(){ System out printin ("As methodAB is executed"): } } class B extends A { private int num = 0: public B (){ super(): System out printin ("B's constructor is executed"):...
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...
1. Look at the following pseudocode algorithm. package javaapplication292 public class JavaApplication292 ( public static void main(StringlI args) recFun(258); public static void recFun( int x) if (x > 10) recFun (x/10); System.out. printIn( x % 10 ); else System.out.println(x); What is the output of the following statements? a. recFun(258); b. recFun (7);
In the following program: public class Problem2{ public static int sample(int x, int y){ int z; ...... } public static void main(String[] args) { int a, b; ...... sample(a,b); } } (1) What is the return type of sample? (2) What are the local variables of sample? (3) What are the parameters of sample? (4) What are the arguments of sample? (5) Is sample a per-object method? Or a per-class method? (6) Is sample a public method, or private method?
What is the output of the following code? Explain your answer. public class Test {public static void main (String [] args) {System.out. print((int) 5.6); System.out.println((int) 5.2);}}
What output is produced by the following program? public class MysteryNums public static void main(String[] args) - int x = 12; int y = x - 3; 3, sentence (y, x + y); . public static void sentence (int numi, int num2) { 4: System.out.println(num1 + " + num2);
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 output public static void main(String args) Scanner keyboard new Scanner(System.in); int u 14; int w 0; int x; int y 5; float z = 6.1 System.out.print("Enter y: "); x keyboard.nextint); System.out.println('y'); System.out.println(x); System.out.println(w*3); x- x+(int)z; System.out.println(x); 0 System.out.println(u); System.out.,println(u); System.out.println"x In" + y); System.out.print(y + z); ) liclosing main method 1 liclosing class header
For the following C# program: Let’s add one more user defined method to the program. This method, called ReverseDump is to output the values in the array in revere order (please note that you are NOT to use the Array.Reverse method from the Array class). The approach is quite simple: your ReverseDump method will look very similar to the Dump method with the exception that the for loop will count backwards from num 1 to 0 . The method header...
2. Write a counter controlled loop to solve the following problems. Each one will involve an array (MinMax.java) Read in 25 ints from the keyboard, and store them in an array. Then, find the maximum and minimum values in such an array, and display them on the screen. public class Array-Assignment { public static void main(String [] args) { int [] x = new int[3]; int [] y = {3, 5, 9, 2}; x[2] = y[3]; ...