Given code:
public static void main(String[] args)
{
int num1=7;
int num2=13;
int result=mystery(num1,num2);
}
public static int mystery(int firstNum,int
secondNum)
{
firstNum=firstNum*3;
secondNum=secondNum*2;
return firstNum+secondNum;
}
ANSWER:
num1 = 7
num2 = 13
result = 47
EXPLANATION: initially num1 and num2 are initilized with some values.
and these two values are passing to the function mystery()
and perform operations on these values:
firstNum=firstNum*3;
secondNum=secondNum*2;
return firstNum+secondNum;
and return the result
I EXECUTE THE ABOVE CODE WITH ADDING SOME PRINT STATEMENTS.
CODE:
public class Main
{
public static void main(String[] args)
{
int num1=7;
int num2=13;
System.out.println("The num1: "+num1);
System.out.println("The num2:
"+num2);
int result=mystery(num1,num2);
System.out.println("The result:
"+result);
}
public static int mystery(int firstNum,int
secondNum)
{
firstNum=firstNum*3;
secondNum=secondNum*2;
return firstNum+secondNum;
}
}
OUTPUT:
SCREENSHOT OF THE CODE:
mystery (numi, num2) ? public static void main(String[] args) int numl = 7; int num2 =...
Please answer both questions thank you. Question 49 (1 point) What is wrong with the following code snippet? for (int i 1; i <= 5; i++) { int squared = i + i; System.out.println(i + IT "! squared = + squared); } System.out.println("Last square = " + squared); calculation error variable scope error O nothing incorrect use of for loop Question 47 (1 point) What are the values of num1 and num2 and result after the execution of mystery (num1,...
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);
What does this program print? package javaapplication210; public class JavaApplication210 { public static void main(String[]args){ System.out.printf("Result is: % d/n", mystery (-5, -9));//System.out.printf("Result is: % d/n", mystery (-4, -8));//System.out.printf("Result is: % d/n", mystery (-6, -7));//} public static int mystery(int a, int b) { if(b - 1) returns a; else return a + mystery(a, b + 1); } }
What are the errors in this ? public class Mystery { public static void main(String[] args) { double initialSavings = 10000; double interestRate = 0.05; double currSavings = 0; int i; System.out.println("\nAnnual savings 5 years: "); currSavings = initialSavings; for (i = 0, i < 5, ++i); currSavings = (currSavings * interestRate); System.out.println("$" + currSavings); } }
how to change this code to string instead of int public static void main(String[] args) { int[] sample = { 212, 580, 6, 7, 28, 84, 112, 434}; Dictionary bst = new Dictionary(); for (int x : sample) { bst.insert(x); } System.out.println(bst.find(65)); System.out.println(bst.smallest()); System.out.println(bst.largest()); // bst.delete(84); System.out.println(bst.numOfLeafNodes()); System.out.println(bst.height()); bst.traverseInOrder(); } }
What is printed by running the following code? public static void main(String[] args) { int[] nums = {2, 3, 4}; int n = 5; changeMe1(n, nums); System.out.print( n ); System.out.print(nums[0]); changeMe2(n, nums); System.out.print( n ); System.out.print(nums[0]); } public static void changeMe1(int number, int[] list) { number++; list[0]++; } public static void changeMe2(int number, int[] list) { number = 9; list = new int[1]; list[0] = 99; }
Java, how would i do this public static void main(String[] args) { int n = 3; int result; result = factorial(n); + public static int factorial(int n) public static int factorial(int n) n = 3 { returns 3* 2 * 1 { if (n == 1) return n; else return (n * factorial(n-1)); if (n == 1) return n; else return (3 * factorial(3-1)); ܢܟ } public static int factorial(int n) n = 2 public static int factorial(int n) returns...
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"); } }
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...
import java.util.Arrays; public class lab { public static void main(String args[]) { int arr[] = {10, 7, 8, 9, 1, 5,6,7}; int arr2[] = {9, 8, 7, 6, 5, 4, 3, 2, 1}; int arr3[] = {1, 3, 5, 3, 2, 6, 20}; quicksort(arr,0,arr.length-1); quicksort(arr2,0,arr2.length-1); quicksort(arr3,0,arr3.length-1); System.out.println(Arrays.toString(arr)); System.out.println(Arrays.toString(arr2)); System.out.println(Arrays.toString(arr3)); } private static int partition(int[] items,int low, int high) { int i=0; int j=0;...