我一直在尝试使此脚本仅在进行某些审查时才能工作,但我似乎没有做任何事情使它超过一定程度。在这里说要按“ r”一个随机数。当我按“ r”时,什么都没有发生,就像我没有激活方法或者我写错了它们。这是代码:
package temper2;
public class temp2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
TempTheRest o = new TempTheRest();
}
}
package temper2;
import java.util.Random;
import java.util.Scanner;
public class TempTheRest {
public String number1;
public TempTheRest()
{
Scanner s = new Scanner(System.in);
System.out.println("Pick a number 1 - 9");
int number = s.nextInt();
System.out.println(number + " is a good number but your choosing privileges have been revoked ");
System.out.println("We will use a random number");
System.out.println("Press 'r' for a random number ");
number1 = s.next();
if(number1 == "r")
{
//randomMethod2();
randomMethod();
System.out.println(randomMethod());
}
}
public static String randomMethod2()
{
String rv = "";
String string1 = randomMethod();
rv = rv + string1;
return rv;
}
public static String randomMethod()
{
String rv = "";
Random r = new Random();
for(int i = 0; i >= 9; i++)
{
int number1 = r.nextInt(8) + 1;
if(number1 > 0 && number1 <= 3)
{
rv = "Your number is " + number1 + " and fell in the first third";
} else if(number1 >= 4 && number1 <= 6)
{
rv = "Your number is " + number1 + " and fell in the second third";
} else if( number1 >= 7 && number1 <= 9)
rv = "Your number is " + number1 + " and fell in the last third";
}
return rv;
}
}
非常感谢所有帮助。谢谢。