Assignment #117 and More Number Puzzles
Code
/// Name: Graham Pollock
/// Period: 5
/// Program Name: More Number Puzzles
/// File Name: MNP.java
/// Date Finished: 04/26/2016/
import java.util.Scanner;
public class MNP
{
public static void main(String[] args)
{
Scanner kb = new Scanner(System.in);
int choice;
do
{
System.out.println("1.) Find two digit numbers <= 56 with sums of digits > 10");
System.out.println("2.) Find two digit number minus number reversed which equals sum of digits");
System.out.println("3.) Quit");
System.out.println("");
System.out.print("> ");
choice = kb.nextInt();
if (choice == 1)
f1();
else if (choice == 2)
f2();
else
System.out.print("");
} while (choice != 3);
}
public static void f1()
{
for (int a = 1; a <= 5; a++)
{
for (int b = 0; b < 10; b++)
{
int n1 = (10 * a) + b;
int s = a + b;
if (s > 10 && n1 <= 56)
{
System.out.println(a + "" + b);
}
}
}
}
public static void f2()
{
for (int a = 1; a < 10; a++)
{
for (int b = 0; b < 10; b++)
{
int n1 = (a * 10) + b;
int n2 = (b * 10) + a;
if (n1 - n2 == a + b)
{
System.out.println(a + "" + b);
}
}
}
}
}
Picture of the output