Why this program is not running. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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); }

13th Feb 2021, 12:26 AM
❤️😍Prerana😍❤️
❤️😍Prerana😍❤️ - avatar
7 Answers
+ 1
This will works
13th Feb 2021, 12:59 AM
❤️😍Prerana😍❤️
❤️😍Prerana😍❤️ - avatar
+ 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); } }
13th Feb 2021, 1:05 AM
❤️😍Prerana😍❤️
❤️😍Prerana😍❤️ - avatar
+ 1
Is this right
13th Feb 2021, 1:06 AM
❤️😍Prerana😍❤️
❤️😍Prerana😍❤️ - avatar
+ 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
13th Feb 2021, 1:07 AM
Benjamin Jürgens
Benjamin Jürgens - avatar
+ 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
13th Feb 2021, 1:10 AM
Benjamin Jürgens
Benjamin Jürgens - avatar
+ 1
Ok
13th Feb 2021, 1:13 AM
❤️😍Prerana😍❤️
❤️😍Prerana😍❤️ - avatar
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); } }
13th Feb 2021, 12:58 AM
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~ - avatar