Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm trying to write a little game in Java and it keeps popping up error:
cannot find symbol
on in.nextInt. I've got other in.nextInts in my code that work fine so I'm a little stumped.
import java.util.Scanner;
public class Player
{
int difficult = 3;
public Player()
{
}
public void SetDifficult()
{
Scanner in = new Scanner(System.in);
System.out.println("choose your difficulty:\n1. simple\n2. easy\n3. normal\n4. hard\n5. impossible");
difficult = in.nextint();
...
}
What is the reason for getting this error ?
you have:
in.nextint()
you want:
in.nextInt()
with a capital I
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I want to key in a value(int) as a parameter and make a loop from zero until it reaches that number.
Scanner s = new Scanner(System.in);
int m=0;
int a;
a=s.nextInt();
while(a<=10) {
System.out.println(m); m++;
}
while loop must be like this:
while(m<=a) {
...
}
In while condition you need to add m<=10 not a.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
as one of my first java projects, I want to build a mortgage calc.
I was trying to restrict the duration that the user can pick using this code
Scanner numOfPayments = new Scanner(System.in);
while (true) {
System.out.print("Enter number of payments (the number of Years you will be paying the loan):");
short numOfPayments2 = numOfPayments.nextShort();
if (numOfPayments2 >= 1 && numOfPayments3 <= 30) {
numOfPayments3 = (short) (numOfPayments2 * 12);
break;
}
System.out.println("Enter a valid number of years(Between 1 and 30)");
}
It worked with restricting other values, but not for this one.
Thanks in advance
Thanks for #azro for the answer
I should just change numOfPayments3 to numOfPayments2 inside the If statement
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
package scanfFunctionInJava;
import java.util.Scanner;
public class ScannerType {
public static void main(String[] args) {
Scanner sc = new scanner(System.in);
int x = sc.nextInt();
System.out.println("your entered value is = " +x);
}
}
Here:
Scanner sc = new scanner(System.in);
Scanner versus sscanner. Java is case sensitive, and the type you intend to use is named Scanner, not scanner.
In programming, each and any character matters. And the error message probably tells you that scanner is unknown.
Thus the real answer is: carefully read the error messages, and then look out for such subtle issues.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 5 years ago.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Improve this question
import java.util.Scanner;
public class Apples1 {
public static void main(String[] args) {
Scanner bucky = new Scanner(System.in);
System.out.println(bucky.nextln ());
}
}
That's because you haven't imported Scanner. You have tried importing scanner, which does not exist.Try doing
import java.util.Scanner;
Also, the System.in also has a Capital S in the beginning.Lastly, there doesn't exist nextln method in the Scanner class. I suppose you intended doing :
System.out.println(bucky.nextLine());
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I need your help quickly!
I have this small for loop and it says "Cannot find symbol i" or something, but I did defined it in the loop.
for(short i=0;i<pin.length;i++)
if (pin[i].getName().equals(x))
System.out.println("Όνομα"+"\t"+"Μήκος"+"\t"+"Πλάτος"+"\t"+"Εκτόπισμα"+"\t"+"Έτος Κατασκευής"+"\t"+"Μέγιστη Ταχύτητα"+"\t"+"Όνομα ιδιοκτήτη");
System.out.println("name"+"\t"+pin[i].getLength()+"\t"+pin[i].getWidth()+"\t"+pin[i].getDisplacement()+"\t"+pin[i].getYear()+"\t"+pin[i].getSpeed()+"\t"+pin[i].getOwners_name());
}
you need to add {} to define your scopes
for(short i=0;i<pin.length;i++) {
if (pin[i].getName().equals(x)) {
System.out.println("Όνομα"+"\t"+"Μήκος"+"\t"+"Πλάτος"+"\t"+"Εκτόπισμα"+"\t"+"Έτος Κατασκευής"+"\t"+"Μέγιστη Ταχύτητα"+"\t"+"Όνομα ιδιοκτήτη");
System.out.println("name"+"\t"+pin[i].getLength()+"\t"+pin[i].getWidth()+"\t"+pin[i].getDisplacement()+"\t"+pin[i].getYear()+"\t"+pin[i].getSpeed()+"\t"+pin[i].getOwners_name());
}
}