Sample Run
/*
* Project done by Anusha PaulChoudhury in IX - Target ICSE 2017
*/
package ix.anusha.proj;
//import java.io.IOException;
import java.util.Scanner;
/**
*
* @author Anusha PaulChoudhury
* Project IX for ICSE 2017
*/
public class IXAnushaProj {
/**
* @param args the command line arguments
*/
public static void main(String[] args)/* throws IOException */{
// TODO code application logic here
mainmenu();
}
public static void mainmenu()
{
Scanner sc = new Scanner(System.in);
int anushaschoice;
boolean quit = false;
do
{
System.out.println("MAIN MENU");
System.out.println("1. Number Problems ");
System.out.println("2. Series ");
System.out.println("3. Nested Loops (Patterns) ");
System.out.println("4. Single Dimensional Arrays ");
System.out.println("5. Exit ");
System.out.println("Enter your choice ");
anushaschoice = sc.nextInt();
switch(anushaschoice) {
case 1:
numbers();
break;
case 2:
series();
break;
case 3:
patterns();
break;
case 4:
OneDArrays();
break;
case 5:
quit=true;
}
}while(!quit);
}
public static void numbers()
{
Scanner sc = new Scanner(System.in);
int anushasnumchoice;
boolean qnum = false;
do
{
System.out.println("1. Magic Number ");
System.out.println("2. Automorphic Number ");
System.out.println("3. Odius Number ");
System.out.println("4. Rhonda Number ");
System.out.println("5. Exit to main menu...");
System.out.println("Enter your choice ");
anushasnumchoice = sc.nextInt();
switch(anushasnumchoice) {
case 1:
magic();
break;
case 2:
automorphic();
break;
case 3:
odius();
break;
case 4:
rhonda();
break;
case 5:
qnum=true;
}
}while(!qnum);
}
public static void magic()
{
System.out.println("This is a Magic Number");
}
public static void automorphic()
{
//System.out.println("This is an automorphic number number");
double itssquare, lengthofnum=0, onezeros;
long i, it, number, onez;
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number ");
number = sc.nextInt();
//find the square
itssquare=Math.pow(number, 2);
it=Math.round(itssquare);
System.out.println("Square of "+number+" is "+it);
//find the length
for(i=number; i>0; i/=10)
{
lengthofnum++;
if(lengthofnum==0) {
lengthofnum=1;
}
}
onezeros=Math.pow(10, lengthofnum);
onez=Math.round(onezeros);
if(it%onez==number) {
System.out.println("It's a automorphic number");
}
else {
System.out.println("It's not a automorphic number");
}
}
public static void odius()
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number ");
int num = sc.nextInt();
int k, bone=0;
for(int l=num;l>0;l/=2)
{
k=l%2;
if(k==1) {
bone++;
}
}
if(bone%2==1) {
System.out.println("It's an Odius number");
}
else {
System.out.println("It's not an Odius number");
}
}
public static void rhonda()
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter a number ");
int numrhonda = sc.nextInt();
int backup=numrhonda;
int multnumrhonda=1, val;
while(numrhonda>0)
{
val=numrhonda%10;
multnumrhonda *=val;
numrhonda /= 10;
}
System.out.println("Successive multiplication values of the digits of the number are "+multnumrhonda+ " ");
System.out.print("The Prime Factors of "+backup+" are : ");
int i=2;
int sum=0;
numrhonda=backup;
while(numrhonda>1)
{
if(numrhonda%i == 0)
{
System.out.print(i+" ");
sum += i;
numrhonda=numrhonda/i;
}
else {
i++;
}
}
System.out.println("The sum of the prime factors of the number "+backup+" is : "+sum);
System.out.println("Ten times the sum of the prime factors of the number "+backup+" is : "+10*sum);
if(sum*10==multnumrhonda) {
System.out.println("So it's a Rhonda number");
}
else {
System.out.println("It's not a Rhonda number");
}
}
public static void series()
{
Scanner sc = new Scanner(System.in);
int anushasserchoice;
boolean qser = false;
do
{
System.out.println("1. Series 1 ");
System.out.println("2. Series 2 ");
System.out.println("3. Series 3 ");
System.out.println("4. Series 4 ");
System.out.println("5. Exit to main menu...");
System.out.println("Enter your choice ");
anushasserchoice = sc.nextInt();
switch(anushasserchoice) {
case 1:
series1();
break;
case 2:
series2();
break;
case 3:
series3();
break;
case 4:
series4();
break;
case 5:
qser=true;
}
}while(!qser);
}
public static void series1()
{
System.out.println("This is series1");
}
public static void series2()
{
System.out.println("This is series2");
}
public static void series3()
{
System.out.println("This is series3");
}
public static void series4()
{
System.out.println("This is series4");
}
public static void patterns()
{
Scanner sc = new Scanner(System.in);
int anushaspatchoice;
boolean qpat = false;
do
{
System.out.println("1. Pattern 1 ");
System.out.println("2. Pattern 2 ");
System.out.println("3. Pattern 3 ");
System.out.println("4. Pattern 4 ");
System.out.println("5. Exit to main menu...");
System.out.println("Enter your choice ");
anushaspatchoice = sc.nextInt();
switch(anushaspatchoice) {
case 1:
pattern1();
break;
case 2:
pattern2();
break;
case 3:
pattern3();
break;
case 4:
pattern4();
break;
case 5:
qpat=true;
}
}while(!qpat);
}
public static void pattern1()
{
System.out.println("This is pattern1");
}
public static void pattern2()
{
System.out.println("This is pattern2");
}
public static void pattern3()
{
System.out.println("This is pattern3");
}
public static void pattern4()
{
System.out.println("This is pattern4");
}
public static void OneDArrays()
{
Scanner sc = new Scanner(System.in);
int anushasarrchoice;
boolean qarr = false;
do
{
System.out.println("1. Bubble Sort ");
System.out.println("2. Selection Sort ");
System.out.println("3. Binary Search ");
System.out.println("4. Frequency of Elements ");
System.out.println("5. Exit to main menu...");
System.out.println("Enter your choice ");
anushasarrchoice = sc.nextInt();
switch(anushasarrchoice) {
case 1:
bubblesort();
break;
case 2:
selectionsort();
break;
case 3:
binarysearch();
break;
case 4:
frequencyofelements();
break;
case 5:
qarr=true;
}
}while(!qarr);
}
public static void bubblesort()
{
System.out.println("This is bubblesort");
}
public static void selectionsort()
{
System.out.println("This is selectionsort");
}
public static void binarysearch()
{
System.out.println("This is binarysearch");
}
public static void frequencyofelements()
{
System.out.println("This is frequencyofelements");
}
}