139k views
2 votes
Write Java code to display a dialog box that asks the user to enter his or her desired annual income. Store the input in a double variable and display it in a message dialog box. public class AnnualIncome { public static void main(String[] args) { // Write your Java code here } }

User Rahulrvp
by
3.5k points

1 Answer

12 votes

Answer:

Follows are the code to the given question:

import java.util.*;//import package for user-input

public class AnnualIncome // defining a class AnnualIncome

{

public static void main(String[] as)//defining main method

{

double income;//defining double variable

Scanner obx=new Scanner(System.in);//creating Scanner class for user-input

System.out.print("Please enter your desired annual income: ");//print message

income=obx.nextDouble();//input double value

System.out.println("Your income "+income);//print value

}

}

Output:

Please enter your desired annual income: 98659.89

Your income 98659.89

Explanation:

In this code, a class "AnnualIncome" is declared, and inside the main method, the double variable "income" is defined, that uses the scanner class concept for input the value from the user-end, and in the next step, it uses the print method for asked user to enter value and it uses the print method, that prints income value with the given message.

User Patryk Dobrowolski
by
3.1k points