'(' or '[' expected
You missing a pair of parentheses or didn't close a pair somewhere
!
Logical 'not' operator, and a way to negate a clause
!true
!false
!!true
!!!true
// false
// true
// true
// false
Create a boolean variable with the value of not false.
boolean a = true;
cannot return a value from method whose result type is void
Your code is returning a value when its return type in the method header is void (which isn't supposed to return anything)
autoboxing
The name for the Java compiler's automatic conversion between primitive data types and their corresponding Wrapper classes.
Math.abs(-16);
Math.abs(98.8);
// returns 16
// returns 98.8
Find the minimum value of these 2 values: -2, 2
Math.min(-2, 2);
bad operand types for binary operator '/'
You're trying to divide by something that's not a number.
alist.add("Add me");
An ArrayList named alist is calling a method called "add", which is a built-in method of ArrayLists that adds an item at the end of the list. The method adds the String literal "Add me".
ArrayList ourList = new ArrayList();
ourList.isEmpty();
ourList.add("Hello");
ourList.isEmpty();
ourList.clear();
ourList.isEmpty();
// Line 2: returns true
// Line 4: returns false
// Line 6: returns true
Create 2 String variables s1, s2 with the String literal "hello!" using 2 different syntaxes. Create a third variable s3 that stores the reference to str2.
String s1 = "hello!";
String s2 = new String("hello!");
String s3 = s2;
reached end of file while parsing
Missing a closing curly brace to finish your program
Variable scope
The way you talk about which variables different parts of a program can "see". Loops, conditionals, methods, and classes each have their own scope.
String str = "Hello world!";
str.indexOf("World");
str.indexOf("world");
str.indexOf("hi");
str.indexOf("Hello world!");
// -1
// 6
// -1
// 0
Create an array that stores the numbers from 1 to 10. Then create an ArrayList that stores those numbers backwards. Do all of this within 1 loop.
int[] arr = new int[10];
ArrayList<Integer> list = new ArrayList<Integer>();
for (int i = 1; i <= 10; i++) {
arr[i] = i;
list.add(0, i);
}
<identifier> expected
You have not defined a method around your code. (Fields are ok)
StringIndexOutOfBoundsException
An exception (error) that happens when Java tries to access an index that doesn't exist in a String. Often this happens when the index is negative or greater than the string's length.
What is happening in main?
class Book {
String title;
String author;
Book(String titleFromuser, authorFromuser){
this.title = titleFromuser;
this.author = authorFromuser;
}
public static void main(String[] args){
Book b = new Book("Alice in Wonderland", "Lewis Carroll");
}
}
A new variable called "b", which can only store Book objects, stores a new Book object that initializes the field "title" to the String literal "Alice in Wonderland" and initializes the field "author" to the String literal "Lewis Carroll"
Write an instance method called celsiusToFahrenheit that converts a temperature, stored as an int in degrees fahrenheit, to celsius and returns it. The formula is (°F − 32) × 5/9. Write an overloaded method that converts the temperature (in degrees fahrenheit) stored as a double.
public int celsiusToFahrenheit(int degreesF){
return (degreesF - 32) * (5 / 9);
}
public double celsiusToFahrenheit(double degreesF){
return (degreesF - 32) * (5 / 9);
}