JavaScript

Moderators: None (Apply to moderate this forum)
Number of threads: 2058
Number of posts: 5158

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Need Help With A Simple Program (indexOf)... Posted by LeKtriX on 23 Oct 2002 at 3:50 PM
Hello,

This is the my first message. I joined Programmers Heaven today because I am seeking help in my assignments. I find Java really fun, challenging, and frustrating. I am here to learn and improve my Java skills, so that I could become better :). I am currently having difficulties with an assignment. I need some help because I "think" I am doing something wrong with my loop, but I am not sure. Please take a look at the bottom to further understand what I am saying.

THE OBJECTIVE: Write a program that lets an user enter in any word, and any character in lower case. Print the number of occurrences of that character in the word. Change the word to lower case before finding the number of occurrences in the word.

Lets say a user enters in the word "Canada", and the character "a". The program is supposed to test how many times "a" is in "Canada". Since "a" goes in "Canada" 3 times, it is suppose to print in the output screen 3, correct? This is not what my program does unfortunately. I do not know what to do, but I will post my source code to see if anyone can help me :).

NOTE: In our school, we use c.print instead of system.out, so please do not get confused :)


// The "Chap3Program8" class.
import java.awt.*;
import hsa.Console;

public class Chap3Program8
{
static Console c; // The output console

public static void main (String [] args)
{
c = new Console ();
String word, lowerword;
char letter;
int count, length;
c.println ("Please enter in any word.");
word = c.readString ();
lowerword = word.toLowerCase ();
length = lowerword.length ();
c.println ();
c.println ("Please enter in any lower case character");
letter = c.readChar ();
c.println ();
for (count = 0 ; length > count ; count++)
{
c.println (lowerword.indexOf (letter));
}

} // main method
} // Chap3Program8 class



Report
Re: Need Help With A Simple Program (indexOf)... Posted by LeKtriX on 24 Oct 2002 at 5:51 AM
Please help!!!









: Hello,
:
: This is the my first message. I joined Programmers Heaven today because I am seeking help in my assignments. I find Java really fun, challenging, and frustrating. I am here to learn and improve my Java skills, so that I could become better :). I am currently having difficulties with an assignment. I need some help because I "think" I am doing something wrong with my loop, but I am not sure. Please take a look at the bottom to further understand what I am saying.
:
: THE OBJECTIVE: Write a program that lets an user enter in any word, and any character in lower case. Print the number of occurrences of that character in the word. Change the word to lower case before finding the number of occurrences in the word.
:
: Lets say a user enters in the word "Canada", and the character "a". The program is supposed to test how many times "a" is in "Canada". Since "a" goes in "Canada" 3 times, it is suppose to print in the output screen 3, correct? This is not what my program does unfortunately. I do not know what to do, but I will post my source code to see if anyone can help me :).
:
: NOTE: In our school, we use c.print instead of system.out, so please do not get confused :)
:
:
: // The "Chap3Program8" class.
: import java.awt.*;
: import hsa.Console;
:
: public class Chap3Program8
: {
: static Console c; // The output console
:
: public static void main (String [] args)
: {
: c = new Console ();
: String word, lowerword;
: char letter;
: int count, length;
: c.println ("Please enter in any word.");
: word = c.readString ();
: lowerword = word.toLowerCase ();
: length = lowerword.length ();
: c.println ();
: c.println ("Please enter in any lower case character");
: letter = c.readChar ();
: c.println ();
: for (count = 0 ; length > count ; count++)
: {
: c.println (lowerword.indexOf (letter));
: }
:
: } // main method
: } // Chap3Program8 class
:
:
:
:

Report
hey i have a question (java program deal) Posted by GameTroy on 2 Nov 2002 at 6:59 PM
: Hello,
:
: This is the my first message. I joined Programmers Heaven today because I am seeking help in my assignments. I find Java really fun, challenging, and frustrating. I am here to learn and improve my Java skills, so that I could become better :). I am currently having difficulties with an assignment. I need some help because I "think" I am doing something wrong with my loop, but I am not sure. Please take a look at the bottom to further understand what I am saying.
:
: THE OBJECTIVE: Write a program that lets an user enter in any word, and any character in lower case. Print the number of occurrences of that character in the word. Change the word to lower case before finding the number of occurrences in the word.
:
: Lets say a user enters in the word "Canada", and the character "a". The program is supposed to test how many times "a" is in "Canada". Since "a" goes in "Canada" 3 times, it is suppose to print in the output screen 3, correct? This is not what my program does unfortunately. I do not know what to do, but I will post my source code to see if anyone can help me :).
:
: NOTE: In our school, we use c.print instead of system.out, so please do not get confused :)
:
:
: // The "Chap3Program8" class.
: import java.awt.*;
: import hsa.Console;
:
: public class Chap3Program8
: {
: static Console c; // The output console
:
: public static void main (String [] args)
: {
: c = new Console ();
: String word, lowerword;
: char letter;
: int count, length;
: c.println ("Please enter in any word.");
: word = c.readString ();
: lowerword = word.toLowerCase ();
: length = lowerword.length ();
: c.println ();
: c.println ("Please enter in any lower case character");
: letter = c.readChar ();
: c.println ();
: for (count = 0 ; length > count ; count++)
: {
: c.println (lowerword.indexOf (letter));
: }
:
: } // main method
: } // Chap3Program8 class
:
:
:
:
'-------------------------------------------
hey i have a question... is your program a class or a script? i tried runing it as a script and it did nothing. i was just checking out your program and i don't know much about java other than how to tell the difference between C language. anyway thats all i was wondering.



Moses 1:39 - "For behold, this is my work and my glory-to bring to pass the immortality and eternal life of man.


-Troy






 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.