Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public class Project10 { public static void main(String[] args) { // TODO Auto-generated method stub // boolean numbersunique=false; // boolean numberssumto27=false; // boolean numberisodd=false; //

public class Project10 {

public static void main(String[] args) {

// TODO Auto-generated method stub

// boolean numbersunique=false;

// boolean numberssumto27=false;

// boolean numberisodd=false;

// boolean threextenplacetimes1000=false;

boolean riddlernumber=false;

//=(int)(Math.random()*9000)+1000;

//System.out.println("Random Number "+randomnumber);

//thousandplace=((randomnumber/1000)%10);

//hundredplace=((randomnumber/100)%10);

//tenplace=((randomnumber/10)%10);

//oneplace=(randomnumber%10);

// System.out.println("Thousand "+thousandplace);

// System.out.println("Hundred " +hundredplace);

// System.out.println("Ten "+tenplace);

// System.out.println("One Place "+oneplace);

//while (riddlernumber==false){

for (int i=1000; i<9999;i++)

{

int thousandplace=0;

int hundredplace=0;

int tenplace=0;

int oneplace=0;

int sum=27;

boolean numbersunique=false;

boolean numberssumto27=false;

boolean numberisodd=false;

boolean threextenplacetimes1000=false;

//int randomnumber=(int)(Math.random()*9000)+1000;

thousandplace=((i/1000)%10);

hundredplace=((i/100)%10);

tenplace=((i/10)%10);

oneplace=(i%10);

// do

// {

if ((thousandplace!=hundredplace) && (thousandplace!=tenplace) &&

(thousandplace!=oneplace) && (hundredplace!=tenplace) && (hundredplace!=oneplace)

&& (tenplace!=oneplace))

{

numbersunique=true;

//System.out.println("No Numbers are duplicated");

}

else

riddlernumber=false;

// }while(numbersunique=false);

// do

// {

if ((thousandplace+hundredplace+tenplace+oneplace)==sum)

{

numberssumto27=true;

//System.out.println("Numbers add to 27");

}

else

numberssumto27=false;

// }while(numberssumto27=false);

// do

// {

if ((oneplace==1) || (oneplace==3) || (oneplace==5) || (oneplace==7)

|| (oneplace==9))

{

numberisodd=true;

//System.out.println("Number is odd");

}

// } while (numberisodd=false);

// do

// {

int sum1=tenplace*3;

int holder=thousandplace;

if ((sum1==holder) && (tenplace!=0) && (thousandplace!=0))

{

threextenplacetimes1000=true;

// System.out.println(tenplace+" times 3 = "+thousandplace);

}

// }while (threextenplacetimes1000=false);

if ((threextenplacetimes1000=true) && (numberisodd=true) &&

(numberssumto27=true) && (numbersunique=true))

{

//i=10000;

System.out.println("Random Number "+i);

}

// riddlernumber=false;

//System.out.println("Random Number "+i);

}

//System.out.println("Random Number "+i);

//thousandplace+hundredplace+tenplace+oneplace=27

//3*tenplace=thousandsplace

}

}

I am get my code to work with a for loop instead of a random number, but it only prints out every possible number in the for loop.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Describe how to measure the quality of work life.

Answered: 1 week ago

Question

What attracts you about this role?

Answered: 1 week ago