Assignemnt 117 and More Number Puzzles
Code
/// Name: Xinting Chen
/// Period: 7
/// Program Name: More Number Puzzles
/// File Name: MoreNumberPuzzles.java
/// Date Finished: 5/4/2016
import java.util.Scanner;
public class MoreNumberPuzzles
{
public static void main( String[] args ) throws Exception
{
System.out.println();
int c = 0;
do
{
c = choices();
System.out.println();
if(c==1) optionA();
if(c==2) optionB();
System.out.println();
}
while (c!=3);
System.out.println("Bye.");
}
public static int choices()
{
System.out.print("1) Find two digit numbers <=56 with sums of digits >10\n" +
"2) Find two digit numbers minus number reversed which equals sum of digits\n"+
"3) Quit\n" + "\n" + ">");
Scanner keyboard = new Scanner(System.in);
int answer= 0;
answer = keyboard.nextInt();
if (answer <1 || answer>3)
System.out.println("enter a number between 1 and 3");
return answer;
}
public static void optionA()
{
for ( int i = 1; i < 10; i++)
{
for ( int a = 0;a < 10; a++)
{
if ((i*10+a)<=56 && (i+a>10) )
{
System.out.print(i);
System.out.print(a + " ");
}
}
}
}
public static void optionB()
{
for ( int i = 1; i < 10; i++)
{
for ( int a = 0; a < 10; a++)
{
if ((i*10+a)-(a*10+i)==(i+a) )
{
System.out.print(i);
System.out.print(a+" ");
}
}
}
}
}
Picture of the output