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
I'm just not sure why I'm getting this error, I would appreciate it if you could help me out to find the error. here is the code,
import java.util.Scanner;
public class FirstSelectionProgram {
public static void main(String[] args) {
Scanner key=new Scanner(System.in);
double spent;
System.out.println("Please Enter The Amount That You Have Spent: ");
spent= key.nextDouble();
if (0.01=<spent && spent=<40)
{
System.out.println("you will receive 20% off");
}
else
{
System.out.println("you won't receive anything");
}
}
}
Instead of doing if (0.01=<spent && spent=<40) try if (0.01 <= spent && spent <= 40)
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 19 days ago.
Improve this question
No idea how to fix this and I require expertise. (New to Java)
I'm just testing out different basic operations like if statements etc and already at a wall.
import java.util.Scanner;
public class yes {
public static void main(String[] args)
{
Scanner test = new Scanner(System.in);
System.out.println("What is 5+5? ");
int value = test.nextInt();
if (test = 10)
{
System.out.println("You are correct!");
}
else
{
System.out.println("Error!");
}
}
}
The problem is in the line
if (test = 10)
test is your Scanner instance. It's a bad name, so it's not too surprising that you missed that. Try to get into the habit of naming variables with meaningful names, even if they are long. It'll help you in the long run.
value is what you called the number that you get from your Scanner, so the first step is to fix the name in the if:
if (value = 10)
Once you've done that you'll still get an error, because = is an assignment, but you want to compare two values for equality, which is ==:
if (value == 10)
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
Why an int becomes zero when it exceed the int limit in java?
Eg:
import java.util.Scanner
public class MyClass{
public static void main(Stings [] args){
Scanner sc = new Scanner(System.in);
int x = sc.nextInt(); // enter 50 or higher.
int answer = 1;
while(x>0){
answer = answer*x;
x--;
}
System.out.println(answer);
}
}
At some point answer becomes 0 (integer overflow) and stays 0.
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 6 years ago.
Improve this question
Every time I try and run this code currentCost returns as 0.
I am trying to calculate depreciation # 20% using loops with the value and age of the asset (here a car) from the user. Thank you.
float cost = Integer.parseInt(jTextField2.getText());
int vehicalAge = Integer.parseInt(jTextField3.getText());
float currentCost = 0;
for (int a = 1; a == vehicalAge; a++) {
cost = (float) (cost - (cost * 0.2));
currentCost = cost;
}
JOptionPane.showMessageDialog(this, Float.toString(currentCost));
Problem is in your for loop:
for (int a=1; a==vehicalAge;a++)
it should be
for (int a=1; a<=vehicalAge;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 7 years ago.
Improve this question
What's wrong with my code?
import java.util.Scanner;
class Pali
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.println("\nInserisci una stringa: ");
String p = in.next();
int n = p.lenght();
}
}
I get a "cannot find symbol" error in p variable. Why? Many thanks (sorry,if I did something wrong, it's my first post).
It's a typo:
int n = p.lenght();
Should be p.length();
It is a typo.
int n = p.lenght();
Correction: int n = p.length();
It happens to the best of us.
Use: int n = p.length(); instead of p.lenght();
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 9 years ago.
Improve this question
I've just started working with some programming in java. I'm experimenting with loops and I have a problem with a for-loop where I'm having a hard time finding the mistake. Its saying that "i" is not a variable, even though i made it one in just above. Hope you guys can help!
import java.util.Scanner;
public class Loops {
public static void main(String [] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("Skriv et tal");
int a = sc.nextInt();
for(int i = 0; i <= 9; i++);
{
System.out.println(a + i);
}
}
}
for(int i=0; i<=9;i++);
// ^ get rid of this
should be
for(int i=0; i<=9;i++)
Because of that the for statement ends there and the new block had been started there.
Beware of the ; behind your loop definition. It is an empty statement.