Compilation error, unexpected type. required: variable found: value
Problem
The linegrades.get(i) += currDiff;
Will be processed as;grades.get(i) = grades.get(i) + currDiff;
So basically the value of the sum will be assigned to the grades.get(i) which is not possible. ( As this is a value itself, not a variable)
Solution
What you probably need to change the code as;
grades.set(i, grades.get(i) + currDiff);
Of course I could be wrong about the solution depending on what you exactly want to do here.
Why am I getting the Error: unexpected type required: variable found: value
I believe you are trying to shuffle cards 1000 times randomly, soo the most simplistic approach IMHO would be something like this (assuming your cards are in ArrayList)
private void Shuffle() {
for (int p = 0; p < 1000; p++) {
int rand1 = (int) (Math.random() * 52);
int rand2 = (int) (Math.random() * 52);
Card card1 = cards.get(rand1);
Card card2 = cards.get(rand2);
cards.set(rand1, card2);
cards.set(rand2, card1);
}
}
Error: unexpected type required: variable found: value
In your code, stringSize
is an integer, to store a string like "ok" or "not ok", you should use a String variable. Declare a String variable and store the value in that. For example -
int stringSize = (n_1 + n_2 + n_3);
String message = null;
if (stringSize < 20){
message = "ok";
}else if (stringSize > 20){
message = "not ok";
}
Moreover, String.valueOf() returns the string representation of the parameter where you cannot assign another value. For example, String.valueOf(stringSize)
will return "15" if the value of stringSize
is 15.
How do i get the
stringSize
to print either "ok" or "not ok"?
Just put the following line wherever you want to print the message. [following the example given above]
if(message != null){
System.out.println(message);
}
Related Topics
Use Only One Bufferedreader Object to Read Multiple Files in Java
I Want to Get Time Difference Between Two Time in Milisecond
How to Map an Auto Increment Field in Hibernate
Converting Excel File (Xlsx) into Json
Making a Mocked Method Return an Argument That Was Passed to It
Placing a Jlabel At a Specific X,Y Coordinate on a Jpanel
In Junit 5, How to Run Code Before All Tests
Type Safety: Unchecked Cast from Object to Arraylist<Myvariable>
How to Get Access to Job Parameters from Itemreader, in Spring Batch
Retrieve Integer Values from Excel Using Java
How to Encrypt a String/Stream With Bouncycastle Pgp Without Starting With a File
Filenotfoundexception in Src/Main/Resources
How to Fetch All Links and Click Those Links One by One Using Selenium Webdriver
How to Get the Parent Element Name of a Child Element in Json
Crudrepository and Hibernate: Save(List<S>) VS Save(Entity) in Transaction
Http Post Request With Content Type Application/X-Www-Form-Urlencoded Not Working in Spring