Assignment 117

code

///Name: Mutsu Osoegawa
///Period: 7
///Project Name: More Number Puzzles
///File Name: MoreNumberPuzzles.java
///Date: 5/2/2016

import java.util.Scanner;
public class MoreNumberPuzzles
{
    public static void main( String[] args )
    {
        Scanner keyboard = new Scanner(System.in);
        int response = 0;
        do
        {
            System.out.println();
            System.out.println("1) Find two digit numbers <= 56 with sums of digits > 10");
            System.out.println("2) Find two digit number reversed which equals the sum of digits");
            System.out.println("3) Quit");
            System.out.print("\n>");
            response = keyboard.nextInt();
            System.out.println();
            
            if( response == 1 )
                first();
            else if( response == 2 )
                second();
            else if( response == 3 )
                System.out.println("Goodbye.");
            else 
                System.out.println("Error.");
        }while( response != 3 );
    }
    public static void first()
    {
        for( int a = 1; a <= 5; a++ )
        {
            for( int b = 0; b <= 9; b++ )
            {
                int n1 = (a * 10) + b;
                int sum = a + b;
                
                if( sum > 10 && n1 <= 56 )
                {
                    System.out.print(n1 + " ");
                }
            }
        }
        System.out.println();
    }
    public static void second()
    {
        for( int c = 1; c <= 9; c++ )
        {
            for( int d = 0; d <= 9; d++ )
            {
                int num = (c * 10) + d;
                int rev = (d * 10) + c;
                
                int dif = num - rev;
                int sum2 = c + d;
                
                if( dif == sum2 )
                {
                    System.out.print(num + " ");
                }
            }
        }
        System.out.println();
    }
}