Write a program to display all two digit numbers whose units digit is twice the tens digit .
Example- The numbers 12,24, 36 satisfies the above condition.
Iteration or Loops in Java.
Answers
Answered by
4
Required Answer:-
Question:
- Write a program in Java to display all the two numbers whose unit digit is twice the tens digit.
Solution:
Here comes the program.
public class Number {
public static void main(String[] args) {
System.out.print("Numbers are: ");
for(int i=10;i<100;i++) {
int x=i%10, y=i/10;
if(x==2*y)
System.out.print(i+" ");
}
}
}
Algorithm:
- START
- Iterate a loop in the range 10 to 99.
- Find the last and first digit of each values of 'i'.
- Check if the ones digit is twice the tens digit. If true, display the value of 'i'
- STOP
Refer to the attachment for output ☑.
Attachments:
Similar questions
Computer Science,
2 months ago
Math,
2 months ago
Math,
2 months ago
Science,
4 months ago
English,
4 months ago