Assignment #117

Code

    /*
jack newsom
period 5
program MorePuzzles
filename MorePuzzles.java
date completed 11/16/2015
*/

import java.util.Scanner;

public class MorePuzzles
{
    public static void main( String[] args )
    {
        
        Scanner bot = new Scanner(System.in);
        
        
        System.out.println();
        System.out.println();
        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 minus number reversed which equals sum of digits");
        System.out.println("3) Quit");
        
        String choice = bot.next();
        
        while ( choice.equals("1") == false && choice.equals("2") == false && choice.equals("3") == false )
        {
            System.out.println("You didnt choose a valid option. Try again.");
            
            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");

            choice = bot.next();   
            
        }
        
        while ( choice.equals("3") == false )
        {
            if ( choice.equals("1") == true )
            {
                first();   
            }
            else if ( choice.equals("2") == true )
            {
                second();   
            }
            
            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");

            choice = bot.next();             
        }
        
        System.out.println("See ya!");
        
        

    }
    
    public static void first( )
    {
        for ( int tens = 10; tens <= 50; tens = tens+10 )
        {
            for ( int ones = 0; ones <= 9; ones = ones+1 )
            {
                int actual = tens + ones;
                
                int firstDigit = tens/10;
                
                int secondDigit = ones;
                
                int digitSum = firstDigit + secondDigit;
                
                
                
                if ( digitSum >= 10 && actual <= 56 ) 
                {
                    System.out.print( " " + actual + " " );
                }               
                
                
                
                
                
               
            }
        }
        
        System.out.println();
    }
    
    public static void second( )
    {
        for ( int tens = 10; tens <= 90; tens = 10+tens )
        {
            for ( int ones = 0; ones <= 9; ones = 1+ones )
            {
                int firstDigit = tens/10;
                
                int secondDigit = ones;
                
                int digitSum = firstDigit + secondDigit;
                
                int actual = tens + ones;
                
                int reverse = secondDigit*10 + firstDigit;
                
                if ( digitSum == actual - reverse )
                {
                    System.out.print( actual ); 
                }
                
                
                
            }
        }
        
        System.out.println();
    }
}  
    

Picture of the output