Tuesday
October 21, 2014

Homework Help: Computer Science

Posted by Anonymous on Sunday, March 13, 2011 at 4:42pm.

The digits 0, 1, and 8 look much the same if rotated 180 degrees on the page (turned
upside down). Also, the digit 6 looks much like a 9, and vice versa, when rotated 180
degrees on the page. A multi-digit number may also look like itself when rotated on the
page; for example 9966 and 10801 do, but 999 and 1234 do not.
You are to write a program to count how many numbers from a given interval look like
themselves when rotated 180 degrees on the page. For example, in the interval [1..100]
there are six : 1, 8, 11, 69, 88, and 96.
Your program should take as input two integers, m and n, which define the interval to be
checked, 1 ≤ m ≤ n ≤ 32000. The output from your program is the number of rotatable
numbers in the interval.
You may assume that all input is valid.
Input/output is not from/to files for this question. Keyboard input and screen output is
expected.
Sample Session User input is in italics.
Enter the lower bound of the interval:
1
Enter the upper bound of the interval:
100
The number of rotatable numbers is:
6

I am kind of stuck withe logic... help me please.
Here's what i have done so far...

import java.util.Scanner;


public class j2 {

/**Gaurav Sharma
*Date: Feb 26th 2011
*Rotatable numbers.
*/

public static String reversing(String orNum){
String revVar = "";
int length = orNum.length();
for (int i = 0; i < orNum.length(); i++)
{
revVar+=orNum.charAt(length--);
length--;
System.out.print (revVar);
}return revVar;

}
public static void main(String[] args) {


Scanner sc = new Scanner(System.in);
//input
System.out.println("Enter the lower bound of the interval:");
int lowerbound = sc.nextInt();
System.out.println("Enter the upper bound of the interval:");
int upperbound = sc.nextInt ();
System.out.println ("The number of rotatable numbers is:");
int numofrotate = 0;
int rangevalues = 0;
String orNum;

for (int i=lowerbound; i<upperbound;i++){
orNum = i+"";

/*if (orNum.equals ("9")){
revVar = revVar+"6";
}
if (orNum.equals ("8")){
revVar= revVar+"8";
}
if (orNum.equals ("1")) {
revVar = revVar+ "1";
}
if (orNum.equals ("0")) {
revVar = revVar+"0";
}
if (orNum.equals ("6")){
revVar= revVar+"9";
}
else {
revVar = revVar+"$";
}
///System.out.println(revVar);
}
if (orNum.equals(revVar))
{
numofrotate++;
System.out.print(numofrotate);
}



*/}








}
}

Answer this Question

First Name:
School Subject:
Answer:

Related Questions

Computer Science - The digits 0, 1, and 8 look much the same if rotated 180 ...
Computer Science - The digits 0, 1, and 8 look much the same if rotated 180 ...
Computer Science - The digits 0, 1, and 8 look much the same if rotated 180 ...
6 grade math - Find 3 uppercase letters that look the same when rotated 180 ...
math,geometry - Find 3 upper case letters that look the same when rotated 180 ...
geometry,math - Find 3 upper case letters that look the same when rotated 180 ...
MATH Trouble - I have no idea what this problem means: For how many two-digit ...
math - A 4-digit number. The sum of its digits is 18. The last two digits are 5 ...
MATH - Find 3 upper case letters that look the same when rotated 180 degrees. ...
math,geometry - Find 3 upper case letters that look the same when rotated 180 ...

Search
Members