Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7591615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:41:44+00:00 2026-05-30T20:41:44+00:00

I’ve learned Java for 1 month. I have a question about my code. There

  • 0

I’ve learned Java for 1 month. I have a question about my code.
There is something wrong.If I press 0, the outcomes only has “Computer win” and “Tie” two situation. So as I press 1 and 2, it only comes out two. What’s wrong in here ?

import java.util.Scanner;
public class Hm3 {
public static void main (String[] args) {
    int Computer=0,Player=0,tie=0,compic=0,pscore=0;tie=0;
    int end = 0;
    Scanner scan = new Scanner(System.in);
    while (end < 3) {
        System.out.print("Enter 0 for Scissors, 1 for Rock, and 2 for Paper : ");
        pscore = scan.nextInt();
        compic = (int)(Math.random()*2);

        switch (pscore){            
        case 0 :
            if (compic == 0){
                System.out.println("Tie");
                tie++;
            }else if (compic == 1){
                System.out.println("Computer Win");
                Computer++;
            }else{
                System.out.println("Player Win");
                Player++;
                end++;
            }
            break;
        case 1 :
            if (compic == 0){
                System.out.println("Player Win");
                Player++;
                end++;
            }else if (compic == 1){
                System.out.println("Tie");
                tie++;
            }else{
                System.out.println("Computer Win");
                Computer++;
            }break;
        case 2 :
            if (compic == 0){
                System.out.println("Computer Win");
                Computer++;
            }else if (compic == 1){
                System.out.println("Player Win");
                Player++;
                end++;
            }else{
                System.out.println("Tie");
                tie++;
            }break;
        default :               
            System.out.println("The wrong value");              
            break;
        }      
  }
    System.out.println("");
    System.out.println("The player wins : " + Player);
    System.out.println("The computer wins : " + Computer);
    System.out.println("Tie : " + tie);
 }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T20:41:45+00:00Added an answer on May 30, 2026 at 8:41 pm

    Yes I also believe that the problem is with your random number generation. When dealing with integers I prefer to use this method because there is no rounding or casting involved:

    Random random = new Random(); //create a random object
    
    random.nextInt(3); //will return a random integer from 0 to 2
    

    The number in the parenthesis of the nextInt() method is the range if you want to go from 1 to 3 just alter it to

    random.nextInt(3) + 1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just learned (the hard way) that Java Component s can only have one
I'm a student in Java class and learned something about Java today that made
I'm currently making a pacman game in java. I have a question about the
I recently learned that Unicode is permitted within Java source code not only as
So I'm learning java. I'm one month in and I just learned about constructors.
Ive just learned java and asked a question about my one line calculator it
I just learned about how the Java Collections Framework implements data structures in linked
I learned today that NetBeans 6.5 should have an on-the-fly compilation of (single) Java
Java has compiler checked exceptions . When I made transition to C++, I learned
I was trying to identify the reason behind constants in Java I have learned

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.