Question

(java) Working with two variables: playernum and winningnum player number is the number the user imputs...

(java)

Working with two variables:

playernum and winningnum

player number is the number the user imputs

win num is the winning number(s) to win a prize

when the playnum matches the winnum in any order of 3 digits (123 matches 321, 456 matches 654)

a prize is won.

how can i make a method that computes this without substrings, indexof,

only boolean/ if/else statements

I'm not sure where to start or what to use

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.*;
public class calculate
{
static void Compute_winner(int playernum, int winningnum)
{
int rev_num = 0;
while(playernum > 0)
{
rev_num = rev_num * 10 + playernum % 10;
playernum = playernum / 10;
}
if(rev_num==winningnum)
{
System.out.println("Player win!");
}
else
System.out.println("Player loos!");
}
  
// Driver code
public static void main (String[] args)
{
Scanner in=new Scanner(System.in);
System.out.println("Entter playernum: ");
int playernum=in.nextInt();
System.out.println("Entter winningnum: ");
int winningnum=in.nextInt();
Compute_winner(playernum,winningnum);
}
}

Entter playernum: 123 Entter winningnum: 321 Player win!

Add a comment
Know the answer?
Add Answer to:
(java) Working with two variables: playernum and winningnum player number is the number the user imputs...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java Listed below is code to play a guessing game. In the game, two players attempt...

    Java Listed below is code to play a guessing game. In the game, two players attempt to guess a number. Your task is to extend the program with objects that represent either a human player or a computer player. boolean checkForWin (int guess, int answer) { System.out.println("You guessed" + guess +"."); if (answer == guess) { System.out.println( "You're right! You win!") ; return true; } else if (answer < guess) System.out.println ("Your guess is too high.") ; else System.out.println ("Your...

  • java/javafx assignment: Island Paradise just started running their city lotto. You've been tasked with writing a...

    java/javafx assignment: Island Paradise just started running their city lotto. You've been tasked with writing a program for them. The program is going to allow to user to first select their lotto numbers. The program will then randomly generate the winning lotto numbers for the week and then check the winning numbers against the random ticket the user played in the Lotto to see how many numbers the user guessed correctly. The rules for lotto work as follows: Select 7...

  • Using the Random, write a simulation that will "play" the California Super LOTTO. Your program logic will allow the player to: 1) Pick any 6 integer numbers from 1 - 70. Your logic should prev...

    Using the Random, write a simulation that will "play" the California Super LOTTO. Your program logic will allow the player to: 1) Pick any 6 integer numbers from 1 - 70. Your logic should prevent the player from selecting a value LESS than 1 or greater than 70. The logic should prevent the player from selecting the SAME number (i.e. they cannot have two or more of their selections be the SAME number). 2) Display the players' 6 number selections...

  • This is a basic Java Question referencing Chapter 5 methods. The goal is to make a...

    This is a basic Java Question referencing Chapter 5 methods. The goal is to make a quick program that has the computer guess a number, after which the user will input if they would like to play the easy, medium or hard level. After this point the user will be allowed to guess a certain amount of times, before the computer tells them they are correct, incorrect, and gives them the guessed number. The Question is as follows: Define a...

  • In a game of Tic Tac Toe, two players take turns making an available cell in...

    In a game of Tic Tac Toe, two players take turns making an available cell in a 3 x 3 grid with their respective tokens (either X or O). When one player has placed three tokens in a horizontal, vertical, or diagonal row on the grid, the game is over and that player has won. A stalemate occurs when all the cells on the grid have been filled with tokens and neither player has achieved a win. Write a program...

  • Hello, I am working on a C++ pick 5 lottery game that gives you the option...

    Hello, I am working on a C++ pick 5 lottery game that gives you the option to play over and over. I have everything working right except that every time the game runs it generates the same winning numbers. I know this is an srand or rand problem, (at least I think it is), but I can't figure out what my mistake is. I've tried moving srand out of the loop, but I'm still getting the same random numbers every...

  • Task Algorithms: Pattern Matching (in java) Write a program that gets two strings from user, size...

    Task Algorithms: Pattern Matching (in java) Write a program that gets two strings from user, size and pattern, and checks if pattern exists inside size, if it exists then program returns index of first character of pattern inside size, otherwise it returns -1. The method should not use built-in methods such as indexOf , find, etc. Only charAt and length are allowed to use. Analyze the time complexity of your algorithm. Your solution is not allowed to be> = O...

  • Java Question where in chapter 7 Arrays. Ive done the code but im still having trouble...

    Java Question where in chapter 7 Arrays. Ive done the code but im still having trouble with the inequality Here my code import java.util.Scanner; public class PS10_5 { public static void main(String args[]) { int[] mynum = new int[5]; int count = 0; int[] lottery = {8,13,27,53,54}; Scanner keyboard = new Scanner(System.in); System.out.println("Check your lottery numbers here!"); for(int subscript=0; subscript<5; subscript++) { System.out.println("Enter number " + (subscript +1) + ":"); mynum[subscript] = keyboard.nextInt(); } for(int subscript=0; subscript<5; subscript++) { for...

  • Requirements: 1. You are not allowed to use global variables. 2. Must declare the following two...

    Requirements: 1. You are not allowed to use global variables. 2. Must declare the following two constants public static final int POINTS = 30; public static final int FORFEIT_POINTS = 20; 3. You can implement your own solution but you are required to break down the problem into smaller pieces. 4. You must provide the output for two rounds of game minimum. 5. Since we are using the Random number generator your output will not be exactly like mine. However,...

  • (2 bookmarks) In JAVA You have been asked to write a program that can manage candidates...

    (2 bookmarks) In JAVA You have been asked to write a program that can manage candidates for an upcoming election. This program needs to allow the user to enter candidates and then record votes as they come in and then calculate results and determine the winner. This program will have three classes: Candidate, Results and ElectionApp Candidate Class: This class records the information for each candidate that is running for office. Instance variables: first name last name office they are...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT