conversion problem
hello,
this is my code :
import java.util.Scanner;
public class convert
{
public static int num,counter;
public static void main(String[] args)
{
Scanner input = new Scanner( System.in );
for (counter=1; counter<26; counter++)
{
System.out.println( "Enter integer : " );
num = input.nextInt();
}
}
public void convertToBinary()
{
String bi = Integer.toBinaryString(num);
System.out.println("Binary : " + bi);
}
public void convertToOctal()
{
String oct = Integer.toOctalString(num);
System.out.println("Octal : " + oct);
}
public void displayDate()
{
System.out.printf(convertToOctal(), convertToBinary());
}
//integer to binary
//String bi = Integer.toBinaryString(num);
//System.out.println("Binary : " + bi);
//integer to octal
//String oct = Integer.toOctalString(num);
//System.out.println("Octal : " + oct);
}
}
the error message is : class,interface, or enum expected.
how to do this :
1)Two string array to store binary and octal values.
2)Display values stored in array in tabular format.
hope anyone can help me.
thanks
[1309 byte] By [
vearnsa] at [2007-11-27 11:12:10]

> this is my code :
Learn about [ coed ] tags please.
> the error message is : class,interface, or enum
> expected.
Check your braces. I think there's one missing in the main method. If you indent your code properly, you'd notice.
im really newbie in java.
i tried play around with the codes...
seems the problem become worst...
> seems the problem become worst...
Thanks for that very precise problem description.
I'd check line 23, character 4.
(by the way, it's [ code] tags for sure.)
System.out.println("Octal : " + oct); <-- this line 23
character 4 > t
what u mean ?
Do you know what "irony" is?
sigh....
i know u are good programmer.
and i am a newbie here.
can u plz direct to the point ?
my knowledge in java in only 0.5% and i want to learn this language.
i tried to code and i found error.
so,im asking for help here.
at least i did the code and ask you how to solve it.
Check your brackets, that's those things that look like this "{" or this "}". The number of open brackets "{" must equal the number of close brackets "}" and it looks like you may have one bracket too many.
The typical format of bracket in a class are:
MyClass {
myFirstMethod() {
} //close method
mySecondMethod() {
}//close method
}//close class
> can u plz direct to the point ?
My point was that you should check the curly braces of the main method. Which I thought I told you.
And then you posted "the problem become worst" in reply. How the **** am I supposed to be able to know what you did and what the results were?
And please take the time to write properly spelled replies, or I might consider not to take the time to translate my replies to English either.
> And please take the time to write properly spelled
> replies, or I might consider not to take the time to
> translate my replies to English either.
Quel horreur!
~
import java.util.Scanner;
public class convert
{
public static int num,counter;
public static void main(String[] args)
{
Scanner input = new Scanner( System.in );
for (counter=1; counter<26; counter++)
{
System.out.println( "Enter integer : " );
num = input.nextInt();
public void convertToBinary()
{
String bi = Integer.toBinaryString(num);
System.out.println("Binary : " + bi);
}
public void convertToOctal()
{
String oct = Integer.toOctalString(num);
System.out.println("Octal : " + oct);
}
public void displayDate()
{
System.out.printf(convertToOctal(), convertToBinary());
}
}
}
}
there are 6 open and close brackets !
then...where is the problem ?
ok CocoProgrammeur,dont know how to pronounce your nick..
i checked the braces...seems it has 6 open braces and 6 close braces.
so...what should i do now ?
> so...what should i do now ?
Stop trying to declare methods inside the main method.
~
> i checked the braces...seems it has 6 open braces and 6 close braces
They problem is that they're not at the right place because now you're declaring methods inside methods. Notice how messed-up the indentation is because of that?
I told you there's a brace missing in main, and it's still missing. And down below there's one too many.
> ok CocoProgrammeur,dont know how to pronounce your
> nick..
>
> i checked the braces...seems it has 6 open braces and
> 6 close braces.
>
> so...what should i do now ?
Coco, LOL, that is funny.
Did you not read my post about formatting the brackets in a class? Reread that then look at your code again. You are not following that format.
> Coco, LOL, that is funny.
Sure, Bob.
ok...thank you for your help.
this is my new code.
import java.util.Scanner;
public class convert
{
public static int num,counter;
public static void main(String[] args)
{
Scanner input = new Scanner( System.in );
for (counter=1; counter<26; counter++)
{
System.out.println( "Enter integer : " );
num = input.nextInt();
}
}
public int convertToBinary()
{
String bi = Integer.toBinaryString(num);
System.out.println("Binary : " + bi);
}
public int convertToOctal()
{
String oct = Integer.toOctalString(num);
System.out.println("Octal : " + oct);
}
public void displayDate()
{
System.out.printf(convertToOctal(), convertToBinary());
}
}
and the error message is :
- Capture Output -
"C:\jdk\bin\javac.exe" convert.java
convert.java:30: cannot find symbol
symbol : method printf(int,int)
location: class java.io.PrintStream
System.out.printf(convertToOctal(), convertToBinary());
^
1 error
Terminated with exit code 1
printf() doesn't take two ints.
I'm surprised that it's all you get, because neither of your methods that declare to return int values actually *do* return an int.
> this is my new code.
Bizarro World Error Message Theory: Error messages, whether from the compiler or the runtime, are not your enemy. They are the friend you know will always be honest with you, even when it hurts. They're telling you something's going wrong. Don't panic. It can be fixed. Read the message!
~
> printf() doesn't take two ints.
ic...so...Coco...what you suggest ?
println ?
can u tell me the cause of the problem and the solution for the problem.
it will be easy for me and other readers who have the same problem.
> I'm surprised that it's all you get, because neither
> of your methods that declare to return int values
> actually *do* return an int.
of course thats all that i get coz i am a noob in this arena.
can you give me a sample code beside a long explanation ?
> ic...so...Coco...what you suggest ?
Don't use chat room abbreviations like "ic" when you mean "I see".
> println ?
printf() will work fine, as long as you call it properly.
> can u tell me the cause of the problem and the
> solution for the problem.
The cause of the problem is that the compiler doesn't recognize what you're trying to do (cannot recognize symbol). It's like you told it to gerfmblakaputz, and it's telling you "I don't understand". The compiler has also told you what it doesn't recognize, namely a printf() method that takes only two ints as arguments.
The solution is to call the proper method. The way to determine the proper method is to read the API and use a method that does what you want by calling it with the proper types and number of arguments.
~
> can you give me a sample code beside a long explanation ?
http://java.sun.com/javase/6/docs/api/java/util/Formatter.html
It's an extremely important skill to learn to read the API and become familiar with the tools you will use to program Java. Java has an extensive set of online documentation that you can even download for your convenience. These "javadocs" are indexed and categorized so you can quickly look up any class or method. Take the time to consult this resource whenever you have a question - you'll find they typically contain very detailed descriptions and possibly some code examples.
Java API Specifications
http://java.sun.com/javase/reference/api.jsp
Java SE 6 JDK Javadocs
http://java.sun.com/javase/6/docs/api/
~
> of course thats all that i get coz i am a noob in this arena.
> can you give me a sample code beside a long explanation ?
And if you need detailed step-by-step instructions, that's what the tutorials are for...
http://java.sun.com/docs/books/tutorial/java/index.html
P.S. "coz" generates a "cannot find symbol" error, too.
~
> > ic...so...Coco...what you suggest ?
>
> Don't use chat room abbreviations like "ic" when you
> mean "I see".
>
> > println ?
>
> printf() will work fine, as long as you call it
> properly.
>
> > can u tell me the cause of the problem and the
> > solution for the problem.
>
> The cause of the problem is that the compiler doesn't
> recognize what you're trying to do (cannot recognize
> symbol). It's like you told it to gerfmblakaputz, and
> it's telling you "I don't understand". The compiler
> has also told you what it doesn't recognize, namely a
> printf() method that takes only two ints as
> arguments.
>
> The solution is to call the proper method. The way to
> determine the proper method is to read the API and
> use a method that does what you want by calling it
> with the proper types and number of arguments.
>
> ~
i think this is a free forum where members can say anything as long they understand what it means.
thanks yawmark for the explanation.it gives some light for me who is in darkness.
the solution is great...but can you tell me what should i use beside printf or what should i change in the coding.
i know i need to read the manual,but it contains a lot methods and take a lot of my time.again,im a newbie..
> > this is my code :
>
> Learn about [ coed ] tags please.
>
> > the error message is : class,interface, or enum
> > expected.
>
> Check your braces. I think there's one missing in the
> main method. If you indent your code properly, you'd
> notice.
I like the sound of these "coed" tags. I wish to know more.
> > > ic...so...Coco...what you suggest ?
> >
> > Don't use chat room abbreviations like "ic" when
> you
> > mean "I see".
> >
> > > println ?
> >
> > printf() will work fine, as long as you call it
> > properly.
> >
> > > can u tell me the cause of the problem and
> the
> > > solution for the problem.
> >
> > The cause of the problem is that the compiler
> doesn't
> > recognize what you're trying to do (cannot
> recognize
> > symbol). It's like you told it to gerfmblakaputz,
> and
> > it's telling you "I don't understand". The
> compiler
> > has also told you what it doesn't recognize, namely
> a
> > printf() method that takes only two ints as
> > arguments.
> >
> > The solution is to call the proper method. The way
> to
> > determine the proper method is to read the API and
> > use a method that does what you want by calling it
> > with the proper types and number of arguments.
> >
> > ~
>
> i think this is a free forum where members can say
> anything as long they understand what it means.
Indeed. Hand-in-hand with that, people are free to not bother helping you if you won't express yourself properly. Which is what normally happens. It's up to you to decide whether you value your right to use shorthand more than you do getting actual help :-)
> i think this is a free forum where members can say
> anything as long they understand what it means.
I would think -- given that this is a forum -- you'd be more interested in saying things so other people can understand what it means. When you use chat room abbreviations and slang, you obfuscate your message. The harder you make it for others to read, the less likely you'll get a fast, useful answer.
If that's how you like it, then I (among others) aren't really interested in helping you further. If you expect clear answers to your questions, it would behoove you to ask clear questions.
> the solution is great...but can you tell me what
> should i use beside printf or what should i change in
> the coding.
You can use printf() if you want. You just need to call it correctly. Alternately, you can use println(). Or print(). It's up to you. The more important issue is that you learn how to call methods properly. That way, you'll be better prepared for future coding.
> i know i need to read the manual,but it contains a
> lot methods and take a lot of my time.
And if it's worth it to you, you'll make the time to learn. If you just want someone to do your work for you, well, I'm even less interested in helping.
> im a newbie..
We all were at one time. If you don't want to remain that way forever, take the time to learn.
Best of luck.
~
ok2...by the way...it is a small matter.
argh mann....why java is so complicated.
i think c++ is much easier.
> ok2...by the way...it is a small matter.
>
> argh mann....why java is so complicated.
> i think c++ is much easier.
By all means, use C++ if you find it easier.
~
alrite yawmark,
i will check the websites.
i dont want to use C++ anymore.
my friends told me to learn other language beside C++ and he suggest Java.
so,i take some time to learn what is JAVA and how to use thing thing.
i think yawmark is much friendly than CocoNUT.
i really hate this CocoNUT guy...so EGO...
yawmark give very detail explanation for a beginner like me.
i will try to solve the code.
thanks man..
> alrite yawmark,
> i will check the websites.
> i dont want to use C++ anymore.
> my friends told me to learn other language beside C++
> and he suggest Java.
> so,i take some time to learn what is JAVA and how to
> use thing thing.
>
> i think yawmark is much friendly than CocoNUT.
> i really hate this CocoNUT guy...so EGO...
> yawmark give very detail explanation for a beginner
> like me.
>
> i will try to solve the code.
>
> thanks man..
http://www.grammarworld.com/
sorry for my broken english.
you are so nice =)
> i think yawmark is much friendly than CocoNUT.
> i really hate this CocoNUT guy...so EGO...
CeciNestPasUnProgrammeur is one of the most helpful people on this forum. Taking things personally and insulting people is not a good way to set yourself up to receive good help in the future. I recommend that you try to understand the very useful information that's been given to you in this thread and keep comments like this to yourself.
~
> sorry for my broken english.
>
> you are so nice =)
I try =)
> ok2...by the way...it is a small matter.
>
> argh mann....why java is so complicated.
> i think c++ is much easier.
Blasphemer!
> i think yawmark is much friendly than CocoNUT.
> i really hate this CocoNUT guy...so EGO...
> yawmark give very detail explanation for a beginner
> like me.
Who R U 2 take a pot shot at Ceci? If U did some checking U would C that he is a very helpful person. He did try 2 help U but U didn't listen. I also gave U help that U didn't listen 2 the 1st time. Where is the thanks 2 me?
> > i think yawmark is much friendly than CocoNUT.
> > i really hate this CocoNUT guy...so EGO...
> > yawmark give very detail explanation for a
> beginner
> > like me.
>
> Who R U 2 take a pot shot at Ceci? If U did some
> checking U would C that he is a very helpful person.
> He did try 2 help U but U didn't listen. I also
> gave U help that U didn't listen 2 the 1st time.
>Where is the thanks 2 me?
http://www.grammarworld.com/
:-)
Sorry man,i forget to thanks to u.
I just hate his style.
With his 20k post in this forum,i know he is helpful guy but i just dont like the way he help me.
Every solution that he gave to me is questionable.
How can i listen for explanation that i did not understand ?
Dont expect every people's brains can catchup for what u said in seconds.
I just learn java for less than a month.
If you can guide me like yawmark did,i can understand it.
Thanks to you all.
Peace =)
Ceci was being more helpful to you than you think. He was trying to get you to use your brain to help you to figure out a solution. I guess you just don't see it (and probably never will).
Also, since you are a newbie you may want to post your questions in the New To Java forum.
> I just hate his style.
He's just providing you with the essential information in a very direct manner. It's an efficient way to answer, and you shouldn't take it personally. If you don't like that "style", a technical forum is going to be a very unpleasant place for you.
~