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.)
|