David bought n apples. x percent of these apples are red. Using Java, calculate how many apples are green. n and x are input from console
//DavidApples.java import java.util.Scanner; public class DavidApples { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n; double x; System.out.print("Enter value for n: "); n = scan.nextInt(); System.out.print("Enter value for x: "); x = scan.nextDouble(); int green = (int) (n*(100-x)/100); System.out.println("Number of green apples: "+green); } }
Get Answers For Free
Most questions answered within 1 hours.