| View previous topic :: View next topic |
| Author |
Message |
NumbLove Advanced Cheater
Reputation: 0
Joined: 20 Feb 2007 Posts: 78
|
Posted: Mon Oct 01, 2007 1:23 pm Post subject: can someone help me with java? |
|
|
this is what i have so far
| Quote: |
import TerminalIO.KeyboardReader;
public class lol {
public static void main (String [] args) {
KeyboardReader reader = new KeyboardReader();
System.out.println("numerator is what?");
int numerator = reader.readchar();
int denominator = reader.readchar();
int total = numerator/denominator;
int remainder = numerator % denominator;
System.out.println("The answer is " + total + " r" + remainder +".");
}
}
|
but it does not compile...it is trying to take two input int values and then give an answer and remainder. can someone tell me what i have done wrong
_________________
working on it..
| void wrote: | | happyh wrote: |
3. Will not get banned, because i use private hax and packet edit.
|
LOLOLOLOL
LOLOLOLOL
LOLOLOLOL
LOLOLOLOL
LOLOLOLOL
LOLOLOLOL
LOLOLOLOL
LOLOLOLOL
LOLOLOLOL
LOLOLOLOL
LOLOLOLOL
LOLOLOLOL
LOLOLOLOL
|
|
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Mon Oct 01, 2007 1:38 pm Post subject: |
|
|
take away 1 } at the end
why dont you give us compile errors?
_________________
|
|
| Back to top |
|
 |
NumbLove Advanced Cheater
Reputation: 0
Joined: 20 Feb 2007 Posts: 78
|
Posted: Mon Oct 01, 2007 1:52 pm Post subject: |
|
|
| Quote: |
----jGRASP exec: javac -g C:\Documents and Settings\David\Desktop\JAVA\lol.java
lol.java:8: cannot find symbol
symbol : method readchar()
location: class TerminalIO.KeyboardReader
int numerator = reader.readchar();
^
lol.java:10: cannot find symbol
symbol : method readchar()
location: class TerminalIO.KeyboardReader
int denominator = reader.readchar();
^
2 errors
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.
|
the 2nd } is needed but thanks for the idea
_________________
working on it..
| void wrote: | | happyh wrote: |
3. Will not get banned, because i use private hax and packet edit.
|
LOLOLOLOL
LOLOLOLOL
LOLOLOLOL
LOLOLOLOL
LOLOLOLOL
LOLOLOLOL
LOLOLOLOL
LOLOLOLOL
LOLOLOLOL
LOLOLOLOL
LOLOLOLOL
LOLOLOLOL
LOLOLOLOL
|
|
|
| Back to top |
|
 |
HomerSexual Grandmaster Cheater Supreme
Reputation: 5
Joined: 03 Feb 2007 Posts: 1657
|
Posted: Mon Oct 01, 2007 2:27 pm Post subject: |
|
|
its not readchar()
its ReadChar()
java is case sensitive
_________________
|
|
| Back to top |
|
 |
DeltaFlyer Grandmaster Cheater
Reputation: 0
Joined: 22 Jul 2006 Posts: 666
|
Posted: Mon Oct 01, 2007 4:57 pm Post subject: |
|
|
By conventions, Java methods begin with lower case. So it's not ReadChar, but rather readChar.
To OP:
Java classes have, by convention, the first letter of its name capitalized.
Also, KeyboardReader is not a standard Java class. Input stream reader or the Scanner class introduced in Java 5 should be used.
Also, the method readChar reads, as its name suggests, a character. You should be trying to read in an integer.
Here's your code fixed:
| Code: | import TerminalIO.KeyboardReader;
public class Lol
{
public static void main (String[] args)
{
KeyboardReader reader = new KeyboardReader ();
System.out.println ("numerator is what?");
int numerator = reader.readInt ();
int denominator = reader.readInt ();
int total = numerator / denominator;
int remainder = numerator % denominator;
System.out.println ("The answer is " + total + " r" + remainder + ".");
}
}
|
Here's a the fixed code using input stream:
| Code: | import java.io.*;
public class lol
{
public static void main (String[] args)
{
try
{
BufferedReader in = new BufferedReader (
new InputStreamReader (System.in));
System.out.println ("numerator is what?");
int numerator = Integer.parseInt (in.readLine ());
int denominator = Integer.parseInt (in.readLine ());
int total = numerator / denominator;
int remainder = numerator % denominator;
System.out.println ("The answer is " + total + " r" + remainder + ".");
}
catch (IOException ioe)
{
ioe.printStackTrace ();
}
}
}
|
Here is the fixed code using Scanner:
| Code: | import java.util.*;
public class lol
{
public static void main (String[] args)
{
Scanner sc = new Scanner (System.in);
System.out.println ("numerator is what?");
int numerator = sc.nextInt ();
int denominator = sc.nextInt ();
int total = numerator / denominator;
int remainder = numerator % denominator;
System.out.println ("The answer is " + total + " r" + remainder + ".");
}
}
|
_________________
Wow.... still working at 827... what's INCA thinking?
zomg l33t hax at this place (IE only). Over 150 people have used it, what are YOU waiting for? |
|
| Back to top |
|
 |
|