loading

Real-Life Examples

Java Data Types Example

Here is a practical illustration of how to compute and output the total cost of several things using various data types:

Example

				
					// Create variables of different data types
int items = 50;
float costPerItem = 9.99f;
float totalCost = items * costPerItem;
char currency = '$';

// Print variables
System.out.println("Number of items: " + items);
System.out.println("Cost per item: " + costPerItem + currency);
System.out.println("Total cost = " + totalCost + currency);
				
			
Share this Doc

Real-Life Examples

Or copy link

Explore Topic