Write a program to get details about a car and display it.
Hint: Store the price in double. When displaying, display the price correct to 2 decimal places.
Sample Input 1:
Enter the car name:
amaze
Enter the car no:
3666
Enter the price:
870000.76
Sample Output 1:
Car name:amaze
Car no:3666
Price:870000.76 rs only
Sample Input 2:
Enter the car name:
Swift
Enter the car no:
7866
Enter the price:
550000
Sample Output 2:
Car name:Swift
Car no:7866
Price:550000.00 rs only
Answers
Answer:
you were asking for this program, I hope this helps, because I am also learning programming and J.S Please mark it as the brainliest answer !!!!
Explanation:
import java.util.Scanner;
class GetInputData
{
public static void main(String args[])
{
int num;
float fnum;
String str;
Scanner in = new Scanner(System.in);
//Get input String
System.out.println("Enter a string: ");
str = in.nextLine();
System.out.println("Input String is: "+str);
//Get input Integer
System.out.println("Enter an integer: ");
num = in.nextInt();
System.out.println("Input Integer is: "+num);
//Get input float number
System.out.println("Enter a float number: ");
fnum = in.nextFloat();
System.out.println("Input Float number is: "+fnum);
}
}
Output:
Enter a string:
Chaitanya
Input String is: Chaitanya
Enter an integer:
27
Input Integer is: 27
Enter a float number:
12.56
Input Float number is: 12.56
Explanation:
Hope you understand
please follow me
Answer:
import java.util.Scanner;
class CarDetails
{
public static void main (String[] args) {
/* code */
int carno;
String carname;
float carprice;
Scanner in = new Scanner(System.in);
//Get inputs
System.out.println("Enter the car name:");
carname = in.nextLine();
System.out.println("Enter the car no:");
carno = in.nextInt();
System.out.println("Enter the price:");
carprice = in.nextFloat();
//print outputs
System.out.println("Car name:" +carname);
System.out.println("Car no:" +carno);
System.out.print("Price:");
System.out.printf("%.2f", carprice);
System.out.print(" rs only");
}
}
Explanation:
Very simple to understand.