• 0

Java Help


Question

15 answers to this question

Recommended Posts

  • 0

A quick way off my head, get the substring of the first letter, and the substring of the last part excluding the first letter than make a new string and append the first letter to the end of the latter. You do this in a for loop until the changes you made equals the original word.

Link to comment
Share on other sites

  • 0

man, do your own homework... :p

A good place to start would be to look up the String class in the Java API ;)

The logic is actually easy if you take a look at what methods are available in the String class.

Link to comment
Share on other sites

  • 0

thanks for that link

I was wondering if you know how to do this...

ConsoleWindow c = new ConsoleWindow();

c.out.println("Enter some large integer ");

int num = c.input.readInt();

that is example code that will take an inputed number and put it in the variable num. How do you get a inputted word to get stored in a string because i know a integer cant store a word and in the code c.input.readInt() takes the integer. I was curious if readLine() would work, and after that i think i will be all set.

Link to comment
Share on other sites

  • 0
thanks for that link

I was wondering if you know how to do this...

ConsoleWindow  c = new ConsoleWindow();

c.out.println("Enter some large integer ");

int num = c.input.readInt();

that is example code that will take an inputed number and put it in the variable num. How do you get a inputted word to get stored in a string because i know a integer cant store a word and in the code c.input.readInt() takes the integer. I was curious if readLine() would work, and after that i think i will be all set.

584737672[/snapback]

By the way you are describing it, I believe I have an idea of what kind of Java IDE you are using... (wouldn't happen to be called 'Ready to Program' would it?) in any case, it should read a line as a string.

could aslo be:

c.input.readln();

c.input.readString();

c.input.readLine();

Those are just some logical guesses. :unsure:

Link to comment
Share on other sites

  • 0

Our teacher wants us to use a program called JGRASP (JGRASP.org) but I use that and I bought the academic version of visual studio .net 2003 so I do some work on that as well.

Link to comment
Share on other sites

  • 0

/* Programing Assignment #3: Console Window */

import element.*;

public class Project3

{

public static void main (String[] args)

{

ConsoleWindow c = new ConsoleWindow();

c.out.println("Enter A Word Without Spaces ");

String word = new String (c.input.readString());

int wordlen = word.length();

for(int count=0;count <= wordlen; count++){ String newstr1 = word.Substring(1,6); String newstr2 = word.Substring(0,1); String newword = newstr1.Comcat(newstr2);

c.out.println(newword);

}}}

that is what i got so far but i am still working on the for statement because i believe it is all messed up, any comments or suggestions are greatly appreciated

If anyone wants to try running the program the package that is imported is attached witch gives you the console window. Just unzip it to the same folder the .java and .class files the project are saved to are in.

Link to comment
Share on other sites

  • 0

I would do something like:

String word = new String(c.input.readString());

String currword = new String();

while (!word.equals(currword)) {

//set currword to substring(1) + charAt(0)

}

Link to comment
Share on other sites

  • 0

we have to use a for loop because the for loop uses the length of the word that is placed into the string to determine how many times the loop will run. Thus the word monkey the loop will run 6 times and the word dog it would run 3 times.

Link to comment
Share on other sites

  • 0
we have to use a for loop because the for loop uses the length of the word that is placed into the string to determine how many times the loop will run. Thus the word monkey the loop will run 6 times and the word dog it would run 3 times.

584738104[/snapback]

Hmm, ok, what's it printing out then right now?

Link to comment
Share on other sites

  • 0

So far it only prints enter a word. lol

It needs to be a one class interactive program that accepts a word (or sequence of words without spaces) as input, and then prints out the word in all possible rotated positions, ending with the original word. Here is an example session:

Enter a word without spaces

monkey

onkeym

nkeymo

keymon

eymonk

ymonke

monkey

Link to comment
Share on other sites

  • 0

If anyone is curious the final code for the project is below:

/* Computer Science 121 */

/* Programing Assignment #3: Console Window */

import element.ConsoleWindow;

public class Project3

{

public static void main (String[] args)

{

ConsoleWindow c = new ConsoleWindow();

/* Assigns the variable c to the Console Window Class */

c.out.println("Enter A Word Without Spaces: ");

String word = new String (c.input.readString());

/* Takes the word inputted and assigns to the the variable word */

int wordlen = word.length();

/*Gives the integer wordlen the value of the length of the inputted word */

c.out.println(" "); /* Blank Line */

String newword1;

for(int count=0;count < wordlen; count++)

{

newword1 = word.substring(1); word = newword1 + word.charAt(0);

c.out.println(word);}

/* Prints the rearranged word to the console window */

}}

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.