2013-10-15 80 views
-3

“public static int readInt(String s)”wat在程序中的确如此吗?目前我需要使用其中的4个,但它们都不同,对于我在这里出现的一个,我需要制作一个程序,在该程序中提示用户,如果输入是int,则会显示,然后转到第二个输入为用户,如果正确的话,但如果不是int;如果它的一个double然后打印出“This is not valid ...”,然后再次重复第一个,如果第二个输入不是一个整数,那么对于第二个输入也会做同样的事情。总共有两个用户输入。我该怎么做才能为此制定计划?我很困惑如何使用这个“公共静态int readInt(String s)”。实用程序测试Java

package rationalnumber;

import java.util。*;

公共类实用 { 公共静态INT的readInt(String s)将 {

} 

public static double readDouble(String s) 

/** 
* Generates a random integer between min and max, inclusive 
* Precondition: min <= max 
* @param min lower bound for the random integer 
* @param max upper bound for the random integer 
* @return A random integer 
*/ 
public static int randomInt(int min, int max) 
{ 

} 

/** 
* Computes the gcd between 2 nonnegative integers 
* Precondition: num1 >= 0, num2 >= 0 
* @param num1 The first integer 
* @param num2 The second integer 
* @return the gcd of num1 and num 2, gcd is 1 if both are 0, 
*   gcd is the non-zero number if only one is 0. 
*/ 
public static int gcd(int num1, int num2) 
{ 

} 

这就像代码的一部分....我还需要加上这里的意见以及至今的是我的代码的最后两部分,但我无法启动它没有前两部分。

package rationalnumber;

/** * 为公用事业类测试程序 */ 公共类UtilityTest {

public static void main(String[] args) 
{ 
    String prompt1 = "Enter first integer: "; 
    String prompt2 = "Enter second integer: "; 

    int a = Utility.readInt(prompt1); 
    int b = Utility.readInt(prompt2); 

    int small = Math.min(a, b); 
    int large = Math.max(a, b); 

    System.out.println("A few random integers: "); 
    System.out.println(Utility.randomInt(small, large)); 
    System.out.println(Utility.randomInt(small, large)); 
    System.out.println(Utility.randomInt(small, large)); 
    System.out.println(Utility.randomInt(small, large)); 

    System.out.printf("The gcd of %d and %d is ", a, b); 
    System.out.println(Utility.gcd(Math.abs(a), Math.abs(b)));  
}  

}

在我用这个到底这是在同一个程序,但在

另一个文件夹来运行它。

+1

没有人知道你的应用中有什么'readInt(String s)'。你应该提供一些代码来获得帮助。 – Alex

+1

'Java'与'Javascript'不一样。这个问题与'Javascript'无关。 –

+0

你是从头开始编写程序,还是你的老师给你一个shell? – Zwade

回答

1

打破它:

Public - 表示这是一个公共方法

int - 表示该功能将return的整数

readInt - 函数的名称

String s - 表示该函数采用类型String的参数将被称为s内的功能。

+0

这是有帮助的,但是当我让我的程序...我很困惑如何做到这一点。是否我用一个inpu.next()用于用户输入的wat?像笏,我需要在这个程序中做...因为我试图自己解决它。 – user2804805

0

Public --a公共方法

int - 返回类不整

readInt - 函数的名称,将读取一个字符串并返回它作为一个integer.in程序会读prompt1和prompt2,就像从用户那里获取输入,并将它们存储在int a和int b中。

String s - - 表示该函数接受一个String类型的参数,该参数在函数中被称为s。