Store String Input In Array And Print In Reverse Order
Apr 5, 2014
I have a college question ask me to write a class StringRevert which does the following:
-prompting user for an interger n
-creating an array of n string
-repeatedly read character string from user input and store them in the array until end of array is reached or user input -quit(quit should not saved in array)
-print the string from array in reverse order, from last enter to first enter.
-assume user always supplie correct input
This is what I've done so far but how to get it working.
import java.util.Scanner;
public class StringRevert {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("enter value of n: ");
int n1 = in.nextInt();
String[] n = new String[n1];
Write a Java program that asks the user to store 10 numbers in an array. You should then print the array in the order entered and then print in reverse order. However, instead of putting all the information in the main, you should use a class called PrintIt. The PrintIt class should have an instance variable that is an array to hold the numbers. You should have a method that will print the array in the order entered. You will also need a method to print in reverse oder. Then create a tester class that asks the user to enter 10 numbers and puts them in an array.
So far I've got this.
public class printIt { int i; int [] numArr = new int [10]; public printIt () { i = -1;
[Code] .....
Output:
Enter a number:
8 34
Forward:
8 34
Reverse:
34 8
end
what i want as an number is being able to print out 10 numbers but this only lets me do two numbers. Why is that so?
I am trying to do this assignment but I can't get the needed output.
Create a program that asks the user how many floating point numbers he wants to give. After this the program asks the numbers, stores them in an array and prints the contents of the array in reverse order.
Program is written to a class called ReverseNumbers.
Example output
How many floating point numbers do you want to type: 5
Type in 1. number: 5,4 Type in 2. number: 6 Type in 3. number: 7,2 Type in 4. number: -5 Type in 5. number: 2
Given numbers in reverse order:
2.0 -5.0 7.2 6.0 5.4
Java Code:
import java.util.Scanner; public class apples { public static void main(String[] args) { Scanner reader = new Scanner(System.in); double[] numbers;
Write an application, HiFour that prompt for four names and then prints the greetings, but with the names in reverse order and with punctuation as shown in the example.
I'm trying to make this code's output display like a sentence, since right now it displays downward and doesn' look right.
public class ReverseOrder { public static void main(String[] args) { String phrase = "The rain in Spain falls mainly on the Plain"; char[] phraseArray; phraseArray = phrase.toCharArray(); for(int i = phraseArray.length - 1; i >= 0; i--){ System.out.println(phraseArray[i]); } } // end main } // end ReverseOrder class
public class ReverseOrder { public static Scanner input = new Scanner(System.in); public static void main(String[] args){ int[] numbers; double[] reverse;
I had to make a program that allowed the user to enter the number of students and the students names and grades and then print out the name with the grade in descending order. right now I only have it where it prints the names out in descending order. how do I get it the print out with the grade?
Here is my code
import java.util.*; public class Grades { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("Enter the number of students: "); int numofstudents = input.nextInt();
The point of this program is to read characters from a txt file and store them into a 2D array. After this has been accomplished, the information is to be printed in the same manner it is read from in the txt file.
Here is the code I have so far:
import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class Main { public static void main(String[] args) throws FileNotFoundException
[Code] ....
And this is the error I am receiving when trying to accomplish the goal of the project:
Exception in thread "main" java.lang.NumberFormatException: For input string: "############" at java.lang.NumberFormatException.forInputString(Unk nown Source) at java.lang.Integer.parseInt(Unknown Source) at java.lang.Integer.parseInt(Unknown Source) at Maze.<init>(Maze.java:15) at Main.main(Main.java:20)
What's going on here and how I can correct this?? The information I am trying to store in a 2D array and then print is this:
This is what I have to do:Write a program that takes a string of someone's name and prints it out last name first. Your program must use pointers, not array subscripts. You may use the available string manipulation functions if you find an opportunity.
Example:
"George Washington" "Washington, George"
I am not sure how to reverse the name, I have been looking in my textbook and online and cannot figure it out. This is what I have put together so far, it does not run. At the end it says unnecessary return value.
import java.util.*; import java.util.Scanner; public class Test { public static void main ( String [] args ) { Scanner sc = new Scanner(System.in); System.out.print("Enter name: "); String name = sc.nextLine(); String lastname = ""; String firstname = ""; for(int i = 0; i < name.length(); i++) { if(name.charAt(i) == ' ')
I want to write an application that inputs a sentence, tokenizes the words with method split and reverse the words (not the letters)...I am stuck at the last part: how to reverse them...should I use the method reverse(); ?
Here is my code..
import java.util.Scanner; import java.util.StringTokenizer; public class ReversedWords { //execute application public static void main( String [] args) { //get sentence
I have the following double linked list and I'm supposed to order it descending (reverse) using the printInReverse() method; since the list orders itself ascending when the numbers are added, how could I order it descending in this method? Here's the code without implementing descending/reversing methods:
Create a class that allows the user to select a file and output the contents of the file to the console. Recommend using a text file to display, java files are text files. You may want to put this code in a method to allow you to complete the remainder of this assignment without overwriting your code.
- You should ask the user to enter the full path to your file to make certain you are processing the correct file.
- Modify your code/add a method to display the contents of the file in reverse order. You do not need to reverse the characters on each line but simply output the lines of the file in reverse order.
Hint: read the content of the file into an ArrayList and then traverse the ArrayList.
this is what i go so far.
package classActivity;
import java.io.File; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class Select { public static String enterFilePath()
im trying to make a small program where the user enters their selection choice and it prints out the corresponding information. for example, if they choose "3", i want "3. Soup de Jour" to print out
import java.util.Scanner; public class rest { public static void main(String[] args)
I have to do a small program about parking. In the 2-d array (parking lot), contains different kinds of cars, the user have to :
1)enter which car he wanna move, 2)what direction (w,a,s,d) and after that, 3) how many moves( not out of bound) he wants to make, and finally 4) we print out the new parking lot for his next move
And i am stuck at how to move the car to corresponding position and then prompt user for the next move?
For example:
I want to move A to the right by 1 (d)
擷取.PNG print result: 擷取1.PNG
How do I do that? The code that i have right now
public class CarParkGame { public static void main( String [] args) { String carPark[][] = new String [6][6] ; carPark[0] = new String[] {"A","A","A","0","0","0"}; carPark[1] = new String[] {"b","0","0","0","0","c"}; carPark[2] = new String[] {"b","X","X","0","0","c","<exit>"};
I have written program for rainfall that will store and give total, average, least and most. The program stores the input of rainfall for each month. However at the end it suppose to print out the month with the least and most rainfall. I am getting this on the print for
The month with the most rainfall: [Ljava.lang.String;@79a7bd3b
and for
The month with the least rainfall: [D@7378aae2[Ljava.lang.String;@79a7bd3b
This code is supposed to convert a decimal base number to base 2, 8 or 16. It prints the number but it's supposed to be in the reverse order for example when converting 188 to base 16. it prints CB instead of BC.
package test; import java.util.Scanner; public class Test { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("Enter a positive integer."); int number = input.nextInt();
I just tried to fill an array with some numbers, calculated by a other function.I just tried to print this array as array, but it doesnt work. Maybe its just about the main method.
public static void main(String[] args) { ggT(5); }
I'm having problems with the mid section of the rocket, specifically the bottom part of the mid section:
|../..../..| |.//..//.| |//////|
I'm having difficulty writing the for loop to correctly print the dots. You're supposed to incorporate a constant which allows you to adjust the size of the overall figure. The loop doesn't work when I adjust the size, only when the value of HEIGHT is 3. The loop, however, for some reason works with the top part of the mid section.
This is the for loop for the top section.
for (int dots = 1; dots <= -1 * line + 1 * HEIGHT; dots++) { System.out.print("."); }
This is the for loop for the bottom section.
for (int dots = -1 * line + 1 * HEIGHT; dots <= 1; dots++) { System.out.print("."); }
Usually reversing the iteration of the loop just requires flipping the conditions, right? But it didn't work this time for some reason. Why this doesn't work? I can post the code to my entire program for compiling.
I'm having trouble with a program, reversing numbers. I got the program itself to work! However, I am having an issue with the output.
import java.util.Scanner; public class p1a { public static void main(String[] args) { // TODO Auto-generated method stub Scanner input = new Scanner(System.in); int n; int reverse = 0;
[Code] .....
If I were to input, say 2341, I would get this: The reverse of 0 is 1432
The 0 should have been 2341, or whatever I input. What am I doing wrong?
I tried to move line 21 : (System.out.println("The reverse of " +n+ " is "+reverse);
Above the while loop, but instead get:
The reverse of 2341 is 0
How can I get my input and my result together in the same line?
What I'm trying to do is compare String input to a char array. Let me make it a little more plain, I'm working on a cipher assignment, and my line of thought is this: I will get String input from the user, COMPARE the characters in the string input to an alphabet array, which will then be compared to the cipher array so that the cipher's counterpart can be chosen over the alphabet's. Any way that I might compare the random input keyed in by the user to that alphabet array?
I am trying to change an input String to an array of characters, but it only stores the word before the space into the array. Here is the code:
Scanner scanner = new Scanner(System.in); System.out.println(" Enter text: " ); String text = scanner.next(); char[] characterArray = text.toCharArray(); // convert string to array of characters String char = ""; for( i = 0; i < characterArray.length; i++) { char = char + characterArray[i] } System.out.println(char);
Just typing hello gives me hello, but when I type hello world it does not type in the word "world".I am trying to change an input String to an array of characters, but it only stores the word before the space into the array.Here is the code:
Scanner scanner = new Scanner(System.in); System.out.println(" Enter text: " ); String text = scanner.next(); char[] characterArray = text.toCharArray(); // convert string to array of characters String char = ""; for( i = 0; i < characterArray.length; i++) { char = char + characterArray[i] } System.out.println(char);
Just typing hello gives me hello, but when I type hello world it does not type in the word "world".