+ 3
Why this program is not running.
import java.util.Scanner; public class Program { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int amount = scanner.nextInt(); //your code goes here for(i=0;i<6;i++) if((amount%10)!=0) { amount = amount-1; } amount = amount-payment; } System.out.print( amount); }
7 Respostas
+ 1
This will works
+ 1
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int amount = scanner.nextInt();
int payment = scanner.nextInt();
//your code goes here
for(i=0;i<6;i++)
if((amount%10)!=0) {
amount = amount-1;
}
amount = amount-payment;
System.out.print(amount);
}
}
+ 1
Is this right
+ 1
Undeclared variables: i, payment
Print is outside of function
Additional tips:
The line amount=amount-payment; is outside the loop, will be executed only once (assuming that payment is declared and initialized before)
It looks like you wanted to solve the task to calculate the remaining amount when paying back 10% for 6 months. But your code doesn't implement that. Payment is 10% of amount, so payment=amount*0.1; Then subtract like you did, but inside the loop
+ 1
General advise:
Copy your code to code Playground and add as a link in your question.
And include problem and task description to get more useful help
+ 1
Ok
0
1. prints statement is out of scope , put it inside main method
2. Iterator type is not defind (for loop)
3. There is no variable named payment
//This program will run.
import java.util.Scanner;
public class Program
{
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int amount = scanner.nextInt();
int payment = scanner.nextInt();
//your code goes here
for(int i=0;i<6;i++)
if((amount%10)!=0) {
amount = amount-1;
}
amount = amount-payment;
System.out.print( amount);
}
}