Question

In: Computer Science

I keep getting the error below in zbooks. How can I fix this. Thank You JAVA...

I keep getting the error below in zbooks. How can I fix this. Thank You JAVA

zyLabsUnitTest.java:14: error: cannot find symbol s = MidtermProblems.difference(75, 75);

^ symbol: method difference(int,int) location: class MidtermProblems 1 error

import java.lang.Math;

public class MidtermProblems {

public static String difference(int a, int b) {

int diff = Math.abs(a - b);

String ans = "";

   if (diff == 0) {

ans = "EQUAL";

   } else if (diff > 10) {

ans = "Big Difference " + diff;

   } else if (diff <= 10) {

ans = "Small Difference " + diff;

        }

        return ans;
   }
}


Solutions

Expert Solution

Before using s we have to declare its data type . so, we have to declare 's' as String datatype

Note: in my answer screen shot , in the 19th line I added the datatype to 's' as String

Note: if you need use public before class name

Source Code:

import java.lang.Math;

class MidtermProblems {
   public static String difference(int a, int b) {
       int diff = Math.abs(a - b);
       String ans = "";
       if (diff == 0) {
               ans = "EQUAL";
           }
       else if (diff > 10) {
               ans = "Big Difference " + diff;
           }
       else if (diff <= 10) {
               ans = "Small Difference " + diff;
           }
       return ans;
   }
   public static void main(String[] args) {
      String s = MidtermProblems.difference(75, 75);
      System.out.println(s);
   }
}

Sample output:


Related Solutions

In java, I keep getting the error below and I can't figure out what i'm doing...
In java, I keep getting the error below and I can't figure out what i'm doing wrong. Any help would be appreciated. 207: error: not a statement allocationMatrix[i][j];
Please fix this python script, I keep getting a return outside function error and cannot get...
Please fix this python script, I keep getting a return outside function error and cannot get it to run: def caesar(plainText, shift):     cipherText = "" for char in plainText:     newChar = ord(char) + shift     if newChar > 128:       newChar = newChar % 128     finalChar = chr(newChar)     cipherText += finalChar return cipherText text = input("Enter a message: "); s = input("Enter the distance value: "); print (caesar(text, int(s)));
Can anyone merge these two java programs I keep getting an error can't find main classes....
Can anyone merge these two java programs I keep getting an error can't find main classes. MySorts.java public class MySorts { public static void insertSort(int[] arr) { int i, temp, j; for (i = 1; i < arr.length; i++) { temp = arr[i]; j = i - 1; while (j >= 0 && arr[j] > temp) { arr[j + 1] = arr[j]; j = j - 1; } arr[j + 1] = temp; } } public static void selectSort(int[] arr)...
Java question: I need to fix a point class (code below) Thank you! /** * A...
Java question: I need to fix a point class (code below) Thank you! /** * A point, implemented as a location without a shape. */ public class Point extends Location { // TODO your job // HINT: use a circle with radius 0 as the shape! public Point(final int x, final int y) { super(-1, -1, null); assert x >= 0; assert y >= 0; } }
I'm getting an error message with this code and I don't know how to fix it...
I'm getting an error message with this code and I don't know how to fix it The ones highlighted give me error message both having to deal Scanner input string being converted to an int. I tried changing the input variable to inputText because the user will input a number and not a character or any words. So what can I do to deal with this import java.util.Scanner; public class Project4 { /** * @param args the command line arguments...
I keep getting an error that I cannot figure out with the below VS2019 windows forms...
I keep getting an error that I cannot figure out with the below VS2019 windows forms .net framework windows forms error CS0029 C# Cannot implicitly convert type 'bool' to 'string' It appears to be this that is causing the issue string id; while (id = sr.ReadLine() != null) using System; using System.Collections.Generic; using System.IO; using System.Windows.Forms; namespace Dropbox13 { public partial class SearchForm : Form { private List allStudent = new List(); public SearchForm() { InitializeComponent(); } private void SearchForm_Load(object...
I am getting an error at linen 57 and can't figure out how to fix it....
I am getting an error at linen 57 and can't figure out how to fix it. // Java program to read a CSV file and display the min, max, and average of numbers in it. import java.io.File; import java.io.FileNotFoundException; import java.util.Arrays; import java.util.Scanner; public class Main {     // method to determine and return the minimum number from the array     public static int minimum(int numbers[])     {         int minIdx = 0;         for(int i=1;i<numbers.length;i++)         {             if((minIdx...
Syntax error in C. I am not familiar with C at all and I keep getting...
Syntax error in C. I am not familiar with C at all and I keep getting this one error "c error expected identifier or '(' before } token" Please show me where I made the error. The error is said to be on the very last line, so the very last bracket #include #include #include #include   int main(int argc, char*_argv[]) {     int input;     if (argc < 2)     {         input = promptUserInput();     }     else     {         input = (int)strtol(_argv[1],NULL, 10);     }     printResult(input);...
My code works in eclipse, but not in Zybooks. I keep getting this error. Exception in...
My code works in eclipse, but not in Zybooks. I keep getting this error. Exception in thread "main" java.util.NoSuchElementException at java.base/java.util.Scanner.throwFor(Scanner.java:937) at java.base/java.util.Scanner.next(Scanner.java:1478) at Main.main(Main.java:34) Your output Welcome to the food festival! Would you like to place an order? Expected output This test case should produce no output in java import java.util.Scanner; public class Main {    public static void display(String menu[])    {        for(int i=0; i<menu.length; i++)        {            System.out.println (i + " - " + menu[i]);...
I keep getting the same error Error Code: 1822. Failed to add the foreign key constraint....
I keep getting the same error Error Code: 1822. Failed to add the foreign key constraint. Missing index for constraint 'test_ibfk_5' in the referenced table 'appointment', can you please tell me what is wrong with my code: -- Table III: Appointment = (site_name [fk7], date, time) -- fk7: site_name -> Site.site_name DROP TABLE IF EXISTS appointment; CREATE TABLE appointment (    appt_site VARCHAR(100) NOT NULL, appt_date DATE NOT NULL, appt_time TIME NOT NULL, PRIMARY KEY (appt_date, appt_time), FOREIGN KEY (appt_site)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT