2 Replies - 295 Views - Last Post: 09 October 2012 - 07:27 PM Rate Topic: -----

#1 amanjot24  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 07-October 12

Reverse Array String

Posted 09 October 2012 - 06:41 PM

So, I'm supposed to write a program that reads 10 strings and displays them in reverse order and the strings are supposed to be read into an Array. I designed a code to print this outcome but when i compile the program i receive an error. Im just looking for help fixing the error by maybe determining what is going wrong.

import java.util.*;
public class ReverseOrder
{
	public static void main (String[] args)
	{
		Scanner scan = new Scanner (System.in);
		{
			String[] numbers = new String[10];
			System.out.println ("Please Enter 10 Integers:");
			{
				for (int i = 0; i < numbers.length; i++)
				{
					System.out.print ("");
					numbers[i] = scan.nextString();
				}
				System.out.println ("Numbers in Reverse Order:");
				for (int i = numbers.length -1; i >= 0; i--)
					System.out.println(numbers[i] + " ");
			}
		}
	}
}



and the error I'm receiving is:
Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
	The method nextString() is undefined for the type Scanner

	at ReverseOrder.main(ReverseOrder.java:14)



Is This A Good Question/Topic? 0
  • +

Replies To: Reverse Array String

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8328
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Reverse Array String

Posted 09 October 2012 - 06:46 PM

it is not
scan.nextString();
but
scan.next();
or scan.nextLine();

This post has been edited by pbl: 09 October 2012 - 06:46 PM
Reason for edit:: nextLine() in that context

Was This Post Helpful? 0
  • +
  • -

#3 amanjot24  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 19
  • Joined: 07-October 12

Re: Reverse Array String

Posted 09 October 2012 - 07:27 PM

View Postpbl, on 09 October 2012 - 06:46 PM, said:

it is not
scan.nextString();
but
scan.next();
or scan.nextLine();


oh wow thanks, such a stupid mistake.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1