Course Hive
Search

Welcome

Sign in or create your account

Continue with Google
or
Let's code a WEIGHT CONVERTER in Java! 🏋️
Play lesson

Java tutorial for beginners ☕ - Let's code a WEIGHT CONVERTER in Java! 🏋️

5.0 (4)
40 learners

What you'll learn

This course includes

  • 12 hours of video
  • Certificate of completion
  • Access on mobile and TV

Summary

Keywords

Full Transcript

#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(); } }

Course Hive

Continue this lesson in the app

Install CourseHive on Android or iOS to keep learning while you move.

Related Courses

FAQs

Course Hive
Download CourseHive
Keep learning anywhere