18. int value = 453;19. int d1 = value % 10;20. int d2 = (value / 10) % 10;21. int d3 = (value / 100) % 10;22. System.out.println("" + d1 + d2 + d3);23. }24. }
Question
- int value = 453;19. int d1 = value % 10;20. int d2 = (value / 10) % 10;21. int d3 = (value / 100) % 10;22. System.out.println("" + d1 + d2 + d3);23. }24. }
Solution
This is a piece of Java code. Here's a step-by-step explanation of what it does:
-
int value = 453;This line declares an integer variable namedvalueand assigns it the value of 453. -
int d1 = value % 10;This line declares an integer variable namedd1and assigns it the value of the remainder whenvalueis divided by 10. In this case,valueis 453, sod1is 3 (the last digit of 453). -
int d2 = (value / 10) % 10;This line declares an integer variable namedd2and assigns it the value of the remainder whenvaluedivided by 10 is further divided by 10. In this case,valueis 453, sovalue / 10is 45 (integer division discards the remainder), and45 % 10is 5 (the second last digit of 453). -
int d3 = (value / 100) % 10;This line declares an integer variable namedd3and assigns it the value of the remainder whenvaluedivided by 100 is further divided by 10. In this case,valueis 453, sovalue / 100is 4 (integer division discards the remainder), and4 % 10is 4 (the first digit of 453). -
System.out.println("" + d1 + d2 + d3);This line prints the values ofd1,d2, andd3concatenated together as a string. In this case, it will print "354". -
}and}These are closing braces, likely for a method and a class, but without the rest of the code, it's hard to say for sure.
Similar Questions
Fill the code to convert int to String and then String to int.Code : int x = 9803; //Convert int to String String str1 = ; System.out.println(str1); String str2 = "1894"; //Convert string str2 to int int z = ; System.out.println(z); System.out.println(str);
Write the output of the below code(1 Marks)public static void main(String[] args) { double num = 9032; double val = 0.5; int i = 5; do { num *= val; i *= 10; } while ( i <= 9032 ); System.out.println(num); }
What is the output of the following code snippet?int x = 10;int y = 3;System.out.println(x % y);Question 6Answera.4b.3c.2d.1
write a program in java to display the number after swapping without using third variable
Arrange the below code in correct order :import java.util.Scanner;public static void main(String args[]) {Scanner sc=new Scanner(System.in);public class Main{int num1 = sc.nextInt();System.out.println("The value is "+num1);}}
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.