PROGRAMMING AND CODE


Assignemnt #117

Code

/// Name: Justin Li
/// Period: 7
/// Program Name: More Number Puzzles
/// File Name: MoreNumberPuzzles.java
/// Date Finished: 5/5/2016

import java.util.Scanner;
import java.util.InputMismatchException;

public class MoreNumberPuzzles
{
	public static void main( String[] args ) throws Exception
	{
		System.out.println();

		int choice = 0;

		do
		{
			choice = showMenu();

			System.out.println("\n");

			if (choice==1) optionOne();
			if (choice==2) optionTwo();

			System.out.println("\n");
		}
		while (choice!=3);

		System.out.println("Bye then.");
	}

	public static int showMenu()
	{
		System.out.print("1) Find two digit numbers <= 56 with sums of digits > 10\n" +
				"2) Find two digit number minus number reversed which equals sum of digits\n" +
				"3) Quit\n" +
				"\n" +
				">");

		Scanner keyboard = new Scanner(System.in);

		int num = 0;

		try
		{
			num = keyboard.nextInt();
		}
		catch (InputMismatchException e)
		{
			System.out.println("WRONG INPUT");
		}

		if (num < 1 || num > 3) System.out.println("Enter a number between 1 and 3 !!!!");
		return num;
	}

	public static void optionOne()
	{
		for ( int i = 1; i < 10; i++)
		{
			for ( int j = 0; j < 10; j++)
			{
				if ((i*10+j)<=56 && (i+j>10) )
				{
					System.out.print(i);
					System.out.print(j + "  ");
				}
			}
		}
	}

	public static void optionTwo()
	{
		for ( int i = 1; i < 10; i++)
		{
			for ( int j = 0; j < 10; j++)
			{
				if ((i*10+j)-(j*10+i)==(i+j) )
				{
					System.out.print(i);
					System.out.print(j+"  ");
				}
			}
		}
	}
}
    

Picture of the output

Assignment 1