Nested Loops #117 ( Ze loops ders moar))
Code
/// Name: Amir Salehi
/// Period: 7
/// Program Name: More Number Puzzles
/// File Name:MoreNP.java
/// Date Finished: 5/2/2016
import java.util.Scanner;
public class MoreNP
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
int choice;
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 minus number reversed which equals sum of digits" );
System.out.println( "3) Quit" );
System.out.print( "> " );
choice = keyboard.nextInt();
if ( choice == 1 )
one();
else if ( choice == 2 )
two();
else
System.out.println();
}while ( choice != 3 );
}
public static void one()
{
int x, y;
for ( x = 1; x <= 5; x++ )
{
for ( y = 0; y <= 9; y++ )
{
int n = ( x * 10 ) + y;
if ( x + y > 10 && n <= 56 )
{
System.out.print( x + "" + y + " " );
}
}
}
System.out.println();
}
public static void two()
{
int a, b;
for ( a = 1; a <= 9; a++ )
{
for ( b = 0; b <= 9; b++ )
{
int r = ( a * 10 ) + b;
int s = ( b * 10 ) + a;
if ( r - s == a + b )
{
System.out.print( a + "" + b + " " );
}
}
}
System.out.println();
}
}
Picture(s) of the output