Results 1 to 4 of 4
- 12-07-2008, 02:23 AM #1
Member
- Join Date
- Dec 2008
- Posts
- 2
- Rep Power
- 0
readint() in Console cannot be apllied to (java.lang.String)
public class Hilo
{
public static void main(String[] args)
{
{
do{
int guess;
int num;
num=(int)(Math.random() *101+1);
guess= Console.readInt("Take a guess.");
if (guess>num)
{
System.out.println("Your guess is too high. \n Please guess lower.");
}
else if (guess < num)
{
System.out.println("Your guess is too low. \n Please guess higher.");
}
else
System.out.println("Your guess is correct, good job.");
System.out.println("Thanks for playing the Hi-Low guessing game.");
ans=Console.readChar("Would you like to play again? (y/n)");
}while (ans=='y');
}
}
}
The error reads readInt() in console cannot be applied to (java.lang.String)
I am very new to java, so please explain in detail.
- 12-07-2008, 02:44 AM #2
Console?
What is Console? It hasn't been define o stated in the porgram.
CJSLChris S.
Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.
- 12-07-2008, 02:46 AM #3
Member
- Join Date
- Dec 2008
- Posts
- 2
- Rep Power
- 0
console
import java.io.*;
/** The <B>Console</B> class consists of static methods that allow easy reading
of the basic data types <TT>double</TT>, <TT>int</TT>, and <TT>String</TT>
from standard input. <I>It must be placed in the same directory containing
the source code using it.</I><P>
<B>Usage Example:</B>
<PRE>
System.out.println("Enter a double number: ");
double x = Console.readDouble();
System.out.println("You have entered: " + x);
</PRE>
@author Bert G. Wachsmuth
@version 98/03/10
*/
public class Console
{
/** Reads a single double value from the keyboard. If there is an error, the
program will halt.
@return double
*/
public static double readDouble()
{
String tmpX = readString().trim();
try
{
return (new Double(tmpX)).doubleValue();
}
catch (NumberFormatException ne)
{
System.err.println("Not a double. Quitting ...");
System.exit(-1);
return 0.0;
}
}
/** Reads a single int value from the keyboard. If there is an error, the
program will halt.
@return int
*/
public static int readInt()
{
String tmpX = readString().trim();
try
{
return Integer.parseInt(tmpX);
}
catch (NumberFormatException ne)
{
System.err.println("Not an integer. Quitting ...");
System.exit(-1);
return -1;
}
}
/** Reads a String from the keyboard until RETURN or ENTER key is pressed.
@return String
*/
public static String readString()
{
String string = new String();
try
{
int cc = System.in.read();
while (!((cc == 13) || (cc == 10)))
{
string += (char) cc;
cc = System.in.read();
}
}
catch (IOException e)
{
}
return string;
}
}
- 12-07-2008, 04:24 AM #4
Similar Threads
-
[SOLVED] operator / cannot to applied to java.lang.string,int
By tpyq in forum NetBeansReplies: 3Last Post: 12-01-2008, 05:40 AM -
Error: cannot resolve symbol' on Person (java.lang.String, java.lang.String)
By baltimore in forum New To JavaReplies: 2Last Post: 09-18-2008, 07:30 AM -
<variable>(Java.lang.string) in <classname> cannot be applies to ()
By inksmithy in forum New To JavaReplies: 5Last Post: 01-13-2008, 10:36 PM -
Error: cannot be applied to (java.lang.String)
By carl in forum New To JavaReplies: 1Last Post: 08-05-2007, 06:33 AM -
Can't convert java.lang.String to int.
By Albert in forum AWT / SwingReplies: 2Last Post: 07-13-2007, 05:05 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks