Assignment #117 and More Number Puzzles
Code
///Name: Tim Gibson
///Period: 6
///Project Name: More Number Puzzles
///File Name: Puzzle1.java
///Date Finished: 12/14/15
import java.util.Scanner;
public class Puzzle2
{
public static void main ( String[] args )
{
Scanner kb = new Scanner(System.in);
int choice;
do
{
System.out.print( "1. Find two digit numbers <= 56 with sums of digits > 10 \n2. Find two digit number minus number reversed which equals sum of digits \n3. Quit \n\n>" );
choice = kb.nextInt();
System.out.println();
if ( choice == 1 )
one();
else if ( choice == 2 )
two();
else if ( choice == 3 )
System.out.println("Goodbye");
else
System.out.println("Error. Try Again");
System.out.println();
System.out.println();
} while ( choice != 3 );
}
public static void one()
{
int n=0; //in order to be able to stop at 56
for ( int t = 1; t<=5; t++)
{
for ( int o = 0; o < 10; o++)
{
n++;
if ( t < 5 )
{
if ( (t + o) > 10 )
{
System.out.print(t);
System.out.print(o + " " );
}
}
else if ( t == 5 && o <= 6 )
{
if ( (t + o) > 10 )
{
System.out.print(t);
System.out.print(o + " " );
}
}
}
}
}
public static void two()
{
int x,y,s,d;
for ( int t = 1; t < 10; t++)
{
for ( int o = 0; o < 10; o++)
{
x = ( t * 10 ) + o; //regular two digit number
y = ( o * 10 ) + t; //reversed two digit #
d = x - y;
s = t + o;
if ( s == d )
{
System.out.print(t);
System.out.print(o + " " );
}
}
}
}
}
Picture of the output