Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

introduction to Java / Java for beginners i need codes with only data types, variables and operators. please and thank you. Data Types, Variables, and

introduction to Java / Java for beginners
i need codes with only data types, variables and operators. please and thank you. image text in transcribed
image text in transcribed
image text in transcribed
Data Types, Variables, and Operators Lab Exercise 3 - Separating Digits Problem Description: Write a Java program (Separate 5Digits.java) that first declares an integer variable named number and initializes it with an integer value consisting of five digits. Then the program should separates the number into its individual digits and prints out the digits separated from one another by three spaces each. For example, if you assign the value 31468 to the number variable, the program should print 3 1 4 6 8. Finally, the program adds up the individual digits of the number and displays their sum. For example: 22 Tips: you need to declare six integer variables as follows: int number =?????: // must be initialized (any five digit int digiti: // first digit int digit2: // second digit int digit 3: // third digit int digit4: // fourth digit int digit: // fifth digit Then you need to apply division and reminder operations on the number variable. viset Gede Sample output: number = 31468 Digits in 31468 are 3 1 4 6 8 The sum is 22 number = 90317 Digits in 90317 are 9 0 3 1 7 The sum is 20 Question: What happens when the user assign a value to the number variable that is less than five digits long? Why? What is the output when the user assign 17632 DataTypes, Variables, and Operators Lab Exercise 4 - Splitting double into Integer and Decimal Parts Problem Description: Write a Java program (SplitDouble Number.java) that splits a given double number into the integer and decimal parts. For example, the number 24.4 should be split into 24 and 4 Tips: use type casting to get the integer part Sample output: ah The whole number is: 24.4 integer - 24 decimal = 0.3999999999999986 Question: Why the decimal part is not 42 How this problem be fixed? Dr. Abdulbase Data Types, Variables, and Operators Lab Exercise 5 - Calculating Rectangle Problem Description: Write a Java program (CalRectange.java) that calculates and displays the area and the circumference of a rectangle that its height and width are given in two variables of type double. If the height and width are equal, the program should displays the following message the figure is a square. Use the following formulas to calculate the area and the circumference: area = height x width circumference = 2 x (height + width) Sample output: height = 4.0 width=2.0 Area is 8.0 Circumference is 12.0 ddah height 5.5 width = 5.5 Area is 30.25 Circumference is 22.0 The figure is a square DIY

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Pro SQL Server Wait Statistics

Authors: Enrico Van De Laar

1st Edition

1484211391, 9781484211397

More Books

Students also viewed these Databases questions