View Single Post
Old 04-25-2004, 08:37 AM   #1 (permalink)
scoobydugan
Crazy
 
need help w/java prog

I've been workin on this for a while and I'm stuck... any help you can give me would be greatly appreciated! The program is using 4 methods: main method will allow user to input a sentence stored as a string, backward method will output sentence backward, words method will output the # of words in sentence and repeat method will count how many times the first letter of the sentence appears w/in the sentence. This is what I came up with but I'm stuck.

import javax.swing.*;
public class StringsAndArrays
{//start class
String str,s1,first;
int w,num;
public static void main(String[] args)
{//start main
final int num;
String str,s1;
int w ;
int num[];

s1=JOptionPane.showInputDialog("Input a sentence");

for (w=0;w<str.length();w++)
{
System.out.println("" +w+ "" +str.charAt(w));
}
str = backward();
}//end main

public static String backward ()
{//start backward
str.reverse();
System.out.println("The sentence, after being revised is: " +str);
return str;
}//end backward

public static String words ()
{//start words
System.out.println("The number of words in the sentence is: " +w);
}//end words

public static String repeat ()
{//start repeat
System.out.println(first+" : is repeated: " +num+ " times.");
}//end repeat
}//end class


(for the method that need to count the number of words I'm pretty sure that you count the spaces and add 1... but i dont know how to type it in correctly.)
scoobydugan is offline  
 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62