DEV Community

Cover image for Day 03: Unveiling the Magic of INTRODUCTION in Java, C++, Python, and Kotlin!
Nitin-bhatt46
Nitin-bhatt46

Posted on

1

Day 03: Unveiling the Magic of INTRODUCTION in Java, C++, Python, and Kotlin!

DAY - 03

For more Tech content Join us on linkedin click here

All the code snippets in this journey are available on my GitHub repository. πŸ“‚ Feel free to explore and collaborate: Git Repository

Today’s Learning :-

TAKING INPUT FROM THE USER :-

Here's how WE can take input from the user in Java, Python, Kotlin, and C++:

Java:
In Java, you can use the Scanner class from the java.util package to read input from the user. Or we can take input directly with parse() input in the command line.

Python:
In Python, you can use the input() function to read input from the user.
python

C++:
In C++, you can use the std::cin object from the iostream library to read input from the user. In c we use cin>> to take input. We can use both options but we mostly use the second because we use ( using namespace std ) , so that we don’t have to use std every time.

Kotlin is similar to java but follows some shortcuts. so, let me first finish java Python, c++ which will create a great base for KOTLIN.

Type of casting

Implicit casting :-

Also known as Automatic Type Conversion.
Referred to as promotion when converting from a smaller data type to a larger data type.
Referred to as demotion when converting from a larger data type to a smaller data type.

Explicit Casting :-

Also known as Type Conversion.
In some contexts, it is referred to as downcasting when converting to a narrower data type.
In other contexts, it is referred to as upcasting when converting to a wider data type.

Java:

Implicit Casting: Java performs implicit casting when converting from a smaller data type to a larger data type. For example, converting an int to a double.

int x = 10;
double y = x; // Implicit casting from int to double

Explicit Casting: Java requires explicit casting when converting from a larger data type to a smaller data type, as it may result in loss of precision. For example, converting a double to an int.

double x = 10.5;
int y = (int) x; // Explicit casting from double to int

Python:

Implicit Casting: Python generally performs implicit casting automatically. For example, converting an int to a float or a float to an int.

x = 10
y = float(x) # Implicit casting from int to float

Explicit Casting: Explicit casting in Python is done using constructor functions or conversion functions.

x = 10.5
y = int(x) # Explicit casting from float to int

C++:
Implicit Casting: C++ performs implicit casting when converting from a narrower data type to a wider data type. For example, converting an int to a double.

int x = 10;
double y = x; // Implicit casting from int to double

Explicit Casting: C++ also requires explicit casting when converting from a wider data type to a narrower data type, as it may result in loss of data.

double x = 10.5;
int y = (int) x; // Explicit casting from double to int

Kotlin:

Implicit Casting: Kotlin performs implicit casting in certain scenarios, such as when widening conversions are safe. For example, converting an Int to a Long.

val x: Int = 10
val y: Long = x // Implicit casting from Int to Long

Explicit Casting: Kotlin supports explicit casting using the as operator. For example, converting a Long to an Int.

val x: Long = 10
val y: Int = x.toInt() // Explicit casting from Long to Int

Those questions are written here; all their code snippets are present in GitHub.

Feel free to share this post to enhance awareness and understanding of these fundamental concepts in statistical analysis!

πŸ™ Thank you all for your time and support! πŸ™
Don't forget to catch me daily at 10:30 Am (Monday to Friday) for the latest updates on my programming journey! Let's continue to learn, grow, and inspire together! πŸ’»βœ¨

API Trace View

Struggling with slow API calls? πŸ•’

Dan Mindru walks through how he used Sentry's new Trace View feature to shave off 22.3 seconds from an API call.

Get a practical walkthrough of how to identify bottlenecks, split tasks into multiple parallel tasks, identify slow AI model calls, and more.

Read more β†’

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay