CodeGym
CodeGym University
Learning
Course
Tasks
Surveys & Quizzes
Games
Help
Schedule
Community
Users
Forum
Chat
Articles
Success stories
Activity
Reviews
Subscriptions
Light theme
Question
  • Reviews
  • About us
Start
Start learning
Start learning now
  • All questions
Jaisingh
Level 14
Hyderabad
  • 04.10.2018
  • 2954views
  • 10comments

how to solve this ?

Question about the task Task No. 7 about integer type conversions
Java Syntax,  Level 10,  Lesson 4
Resolved


Remove unnecessary operators to get the correct answer: 1234567
long l = (byte)1234_564_890L;
int x = (byte)0b1000_1100_1010;
double m = (byte)110_987_654_6299.123_34;
float f = (byte)l++ + 10 + ++x - (float)m;
l = (long) f / 1000;

Requirements:
  • The program should display text on the screen.
  • Don't change the screen output command.
  • The main() method must contain a long variable l.
  • The main() method must contain an int variable x.
  • The main() method must contain a double variable m.
  • The main() method must contain a float variable f.
  • Don't change the initial value of the variables during initialization. You can only change the cast operators.
  • The program should display 1234567.
package com.codegym.task.task10.task1007; /* Task No. 7 about integer type conversions */ public class Solution { public static void main(String[] args) { long l = (byte) 1234_564_890L; System.out.println(l); int x = (byte) 0b1000_1100_1010; System.out.println(x); double m = (byte) 110_987_654_6299.123_34; System.out.println(m); float f = (byte) l++ + 10 + ++x - (float) m; System.out.println(f); l = (int) f / 1000; System.out.println(l); } }
0
Comments (10)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Thang Za Thang
Level 18 , Melbourne, Australia
5 July 2020, 01:36
Expected Johannes to be in these comments : (
+4
Dhruv Kale
Level 22 , Vadodara, India
15 June 2019, 04:31solution
long l = (int) 1234_564_890L; int x = (short) 0b1000_1100_1010; double m = (short) 110_987_654_6299.123_34; float f = (float) l++ + 10 + ++x - (float) m; l = (int) f / 1000; System.out.println(l);
+28
Profj
Level 20 , Lagos, Nigeria
15 June 2019, 06:34
Perfect! Thanks.
0
Carlos Cortázar
Level 17 , Madrid, Spain
12 September 2019, 14:27
Thanks Dhruv!!! Now I just ought to understand it!!!
0
MecoS Full Stack Developer at Microsoft
17 December 2019, 12:57
Thanks.. maybe this cast of number aren't my best skill...
0
Nicola
Level 17 , Vienna, Austria
13 June 2019, 19:51
l = (long) f / 1000; //the reminder is ignored so f can be something like 1234567170
0
ulmas9025
Level 20 , Tashkent, Uzbekistan
11 June 2019, 04:52
public class Solution { public static void main(String[] args) { double d = (short) 2.50256e2d; char c = (short) 'd'; short s = (short) 2.22; int i = 150000; float f = 0.50f; double result = f + (i / c) - (d * s) - 500e-3; System.out.println("result: " + result); } }
0
KenCanKode Backend Developer
27 May 2019, 09:44
Check the results in relation to 'double m'
0
Tayyab Mubeen
Level 16 , Lahore, Pakistan
1 November 2018, 18:22
check line number 10 , 11 and 16
+1
Roy
Level 22 , Bangkok, Thailand
22 April 2019, 23:35
10,12 and 16**
+2
Learn
  • Registration
  • Java Course
  • Help with Tasks
  • Pricing
  • Game Projects
  • Java Syntax
Community
  • Users
  • Articles
  • Forum
  • Chat
  • Success Stories
  • Activity
  • Affiliate Program
Company
  • About us
  • Contacts
  • Reviews
  • Press Room
  • CodeGym for EDU
  • FAQ
  • Support
CodeGym CodeGym is an online course for learning Java programming from scratch. This course is a perfect way to master Java for beginners. It contains 1200+ tasks with instant verification and an essential scope of Java fundamentals theory. To help you succeed in education, we’ve implemented a set of motivational features: quizzes, coding projects, content about efficient learning and Java developer’s career.
Follow us
Interface language
Programmers Are Made, Not Born © 2023 CodeGym
MastercardVisa
Programmers Are Made, Not Born © 2023 CodeGym
This website uses cookies to provide you with personalized service. By using this website, you agree to our use of cookies. If you require more details, please read our Terms and Policy.