`Hey,
Note: If you have any queries related the answer please do comment. I would be very happy to resolve all your queries.
public class Errors{
public static void main(String []args){
float sum=0;
float a=27.5f;
double b=72.99;
sum=suma(a,b);
System.out.printf("Suma = %7.3f",sum);
}
public static float suma(float a,double b)
{
float sum;
sum=a+(float)b;
return sum;
}
}//end class
Kindly revert for any queries
Thanks.
FIX THE FOLLOWING JAVA CODE public class Errors public static main(String[] args) { float sum int...
Analyze the following code: public class Test { private int t; public static void main(String[] args) { int x; System.out.println(t); } } t is non-static and it cannot be referenced in a static context in the main method. The program compiles and runs fine. The variable t is not initialized and therefore causes errors. The variable x is not initialized and therefore causes errors.
Analyze the following code: public class Test { private int t; public static void main(String[] args) { int x; System.out.println(t); } } The variable t is private and therefore cannot be accessed in the main method. The program compiles and runs fine. t is non-static and it cannot be referenced in a static context in the main method. The variablet is not initialized and therefore causes errors. The variable x is not initialized and therefore causes errors.
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); } }
Given the following Java code: public static void main (String[] args) { int num; System.out.println("Enter a number"); num = scan.nextInt(); <-first input statement while (num != 0) { System.out.println ("The number is: " + num); System.out.println("Enter a number"); num = scan.nextInt(); } //End While } //End Module The first input statement shown above is called the:
This is for a java program public class Calculation { public static void main(String[] args) { int num; // the number to calculate the sum of squares double x; // the variable of height double v; // the variable of velocity double t; // the variable of time System.out.println("**************************"); System.out.println(" Task 1: Sum of Squares"); System.out.println("**************************"); //Step 1: Create a Scanner object //Task 1. Write your code here //Print the prompt and ask the user to enter an...
Fix 15 errors in the code below public class CallingMethodsInSameClass { string fName = Joe; string lName = Hasley; string fullName; public static void main(String[] args) { printOne() concatThem() } public static void printOne() { System.out.println(Hello World) public static void concatThem() { fullName = fName + “ “ + lName; if(fullName.equals(fName + lName){ system.out.println(“It’s a match! fullName is: “ + fullname”) } else ...
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(); } }
Identify a logical error in the following code and fix it. public class test1 { public static void main(String[] args){ int total; float avg; int a, b, c; a=10; b=5; c=2; total=a+b+c; avg=total/3; System.out.println("Average: "+avg); } } Answer: Write the output of the program below. import java.util.Scanner; public class test2 { public static void main(String[] arg){ int psid; String name; Scanner input=new Scanner(System.in); System.out.println("Enter your PSID"); psid=input.nextInt(); System.out.println("Enter your...
Review the following code: public class Looping { public static void main(String[] args) { for (int i = 1; i <= 5; i++) { for (int j = 1; j <= 5; j++) { System.out.println(i + " x " + j + " = " + (i * j)); } } } } What is the output from the code above? Replace this text with your solution What happens if you change the...
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"); } }