Question

David bought n apples. x percent of these apples are red. Using Java, calculate how many...

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

Homework Answers

Answer #1
//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);
    }
}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
There are 4 balls in a bag: Red, Blue, Green and Yellow. In how many ways...
There are 4 balls in a bag: Red, Blue, Green and Yellow. In how many ways you can pick k balls from the urn of n with replacement?
This is an exercise using a while loop Input an integer n from the keyboard. Calculate...
This is an exercise using a while loop Input an integer n from the keyboard. Calculate the sum of the first n integers. So if n=10, the answer should be 55 (because 1+2+3+4+5+6+7+8+9+10=55) Code language: Java
how many ways are there to choose nineteen identical balls from a pile of red, yellow,...
how many ways are there to choose nineteen identical balls from a pile of red, yellow, blue, and green balls if there can be no more than seven balls of each color?
Using the formual (2n-3)! / [2^n-2 x (n-2)!], how many possible rooted trees can you generate...
Using the formual (2n-3)! / [2^n-2 x (n-2)!], how many possible rooted trees can you generate using 6 organisma?
Please show how to solve using EXCEL ONLY EXCEL INSTRUCTIONS ONLY 8. David Hoffman purchases a...
Please show how to solve using EXCEL ONLY EXCEL INSTRUCTIONS ONLY 8. David Hoffman purchases a $1,000 20‐year bond with an 8 percent coupon rate (annual payments). Yields on comparable bonds are 10 percent. David expects that, 2 years from now, yields on comparable bonds will have declined to 9 percent. Find his expected yield, assuming the bond is sold in 2 years.
Complete the Java ocode. The code should print how many times integer x appears in numbers....
Complete the Java ocode. The code should print how many times integer x appears in numbers. For example, if numbers = {2,2,1,3,2,2} and x = 2, your code should print the number 4, because x appears 4 times in the array public static void main(String[] args){                         int[] numbers = <some array values>;                         int x = <some value>;             }
using java LO: (Remember) Students will recall how to read from standard input. LO: (Apply) Students...
using java LO: (Remember) Students will recall how to read from standard input. LO: (Apply) Students will write loops that iterate as long as a condition is true. Write a program that reads words from standard input and displays them to standard output. When the word "end" is read, print it out and then stop reading input. starter code: import java.util.Scanner; /* * Reads and displays words from standard input until hitting a stop word. */ public class WhileLoop {...
how do you calculate the percent of EBIT over many years? such as five or more...
how do you calculate the percent of EBIT over many years? such as five or more years as a percent.
Using the experimental sampling strategy, how many samples of size 4 (n = 4) can be...
Using the experimental sampling strategy, how many samples of size 4 (n = 4) can be drawn from the following population sizes? (a) N = 6 (b) N = 7 (c) N = 8 (d) N = 9
How many eigenstates in the n=3 energy level for hydrogen atom? How can I calculate this?...
How many eigenstates in the n=3 energy level for hydrogen atom? How can I calculate this? Please explain your all step! Thank you!
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT