tubeshowcase●1,194,391 videos♡ My collection 0
← Learn to Code

Learn to Code08:20

Let's code a WEIGHT CONVERTER in Java! 🏋️

Bro Code ↗

From the creator

#java #javatutorial #javacourse import java.util.Scanner; public class Main { public static void main(String[] args) { // WEIGHT CONVERSION PROGRAM Scanner scanner = new Scanner(System.in); double weight; double newWeight; int choice; System.out.println("Weight Conversion Program"); System.out.println("1: Convert lbs to kgs"); System.out.println("2: Convert kgs to lbs"); System.out.print("Choose an option: "); choice = scanner.nextInt(); if(choice == 1){ System.out.print("Enter the weight in lbs: "); weight = scanner.nextDouble(); newWeight = weight * 0.453592; System.out.printf("The new weight in kgs is: %.2f", newWeight); } else if(choice == 2){ System.out.print("Enter the weight in kgs: "); weight = scanner.nextDouble(); newWeight = weight * 2.20462; System.out.printf("The new weight in lbs is: %.2f", newWeight); } else{ System.out.println("That was not a valid choice"); } scanner.close(); } }

Published 2024-12-05 · Watch on YouTube ↗
Availability and playback restrictions are controlled by the original channel.

Keep exploring Learn to Code