1 import java.util.Scanner; 2 3 public class Solution 4 { 5 public static void main(String[] args) 6 { 7 Scanner input = new Scanner(System.in); 8 System.out.print("Enter the number you do not want to get: "); 9 int number = input.nextInt(); 10 11 input.close(); 12 13 System.out.println("The number we get is: " + getRandom(number)); 14 } 15 16 public static int getRandom(int number) 17 { 18 int returnValue; 19 while(true) 20 { 21 returnValue = (int)(Math.random() * 54 + 1); 22 if(returnValue != number) 23 break; 24 } 25 return returnValue; 26 } 27 }
时间: 2024-10-13 12:07:18