9 Replies - 1397 Views - Last Post: 04 September 2014 - 03:49 PM Rate Topic: -----

#1 Waternorsoap  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 02-September 14

Help with Java assignment

Posted 02 September 2014 - 04:16 PM

Hello all. I've been stuck with this problem for a couple of days now for my intro to Java class and I still don't know what it is. I get this error message Exception java.util.NoSuchElementException: No line found occurred. Here is my code thus far:

import java.util.Scanner;

public class ShoutAndWhisper
{
	public static void main(String[] args)
	{
			Scanner scannerObject = new Scanner (System.in);
			System.out.println("Enter the text:");
			scannerObject.nextLine();
			String toUpperCase = scannerObject.nextLine();
			String toLowerCase = scannerObject.nextLine();
			System.out.println("The text in all upper case is: " + toUpperCase); 
			System.out.println("The text in all lower case is: " + toLowerCase);			
	}					
}




At first I thought to omit the "\n" because it was originally System.out.println("The text in all upper case is: \n" + toUpperCase); but it said "Correct solutions that use 'The text in all upper case is: \n' tend to also use firstString"

Any ideas?

Is This A Good Question/Topic? 0
  • +

Replies To: Help with Java assignment

#2 macosxnerd101  Icon User is online

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12186
  • View blog
  • Posts: 45,250
  • Joined: 27-December 08

Re: Help with Java assignment

Posted 02 September 2014 - 04:34 PM

If you only entered one line of text, then there is nothing for these lines to read in:
String toUpperCase = scannerObject.nextLine();
String toLowerCase = scannerObject.nextLine();



If you want to capitalize/lower-case a String, see the toUpperCase() and toLowerCase() String methods. These return a new String object with the changes:
String newStr = myString.toUpperCase();


Was This Post Helpful? 1
  • +
  • -

#3 RaulV10  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 9
  • Joined: 30-August 14

Re: Help with Java assignment

Posted 02 September 2014 - 08:46 PM

View PostWaternorsoap, on 02 September 2014 - 04:16 PM, said:

Any ideas?


You have to create a String first so you can say
String text;


Then you don't add the scanner to the nextLine();
You add the String
so would be
scannerObject.nextLine() // Wrong;

text.nextLine() // text is the string that we created before;


Same with your code for upper case and lower case:
String toUpperCase = scannerObject.toUpperCase();
String toLowerCase = scannerObject.toLowerCase();

don't use the Scanner, use the String
String toUpperCase = text.toUpperCase();
String toLowerCase = text.toLowerCase();


Just change those codes and it would work fine
Was This Post Helpful? 1
  • +
  • -

#4 22developer  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 65
  • Joined: 26-August 14

Re: Help with Java assignment

Posted 03 September 2014 - 11:06 AM

you should make a string:
string somestring = scannerobject.nextline();  //pauses your program until the user types input and presses Enter.



-hope this helps!
Was This Post Helpful? 1
  • +
  • -

#5 Waternorsoap  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 02-September 14

Re: Help with Java assignment

Posted 03 September 2014 - 02:53 PM

Hey guys. Thanks for all your help. It makes more sense now. However I still get an error The value of _stdout is incorrect.
Here is the updated code:

import java.util.Scanner;

public class ShoutAndWhisper
{
	public static void main(String[] args)
	{
			Scanner scannerObject = new Scanner (System.in);
			System.out.println("Enter the text: ");
			
			String greeting = scannerObject.nextLine();
           
			String toUpperCase = greeting.toUpperCase();
                        
			String toLowerCase = greeting.toLowerCase();
			
                        System.out.println("The text in all upper case is: " + toUpperCase); 
			System.out.println("The text in all lower case is: " + toLowerCase);			
	}					

   
}



Any more help will be greatly appreciated. Thanks!
Was This Post Helpful? 0
  • +
  • -

#6 ChrisNt  Icon User is offline

  • cute bug

Reputation: 262
  • View blog
  • Posts: 896
  • Joined: 31-July 13

Re: Help with Java assignment

Posted 03 September 2014 - 03:45 PM

That error is not coming from this program
Was This Post Helpful? 1
  • +
  • -

#7 mike73  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 250
  • View blog
  • Posts: 918
  • Joined: 24-April 10

Re: Help with Java assignment

Posted 03 September 2014 - 03:50 PM

I just ran your code and it worked fine... So the problem is only on your end. How are you compiling and running it? IDE or text editor/command line?
Was This Post Helpful? 1
  • +
  • -

#8 Waternorsoap  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 02-September 14

Re: Help with Java assignment

Posted 03 September 2014 - 04:01 PM

For this class, we are using MyProgrammingLab to compile our code, which has their own text editor in the browser. Once we have a a justifiable code, we submit and it will give us the results and it'll produce an error if anything is wrong with the code. But I see what you're saying. I ran the code on NetBeans over and over and kept scanning every line, and it goes through with no problems. Maybe its a bug or something. My Professor has yet to email me back for this error.

Thanks guys for all your help. I greatly appreciated it.
Was This Post Helpful? 0
  • +
  • -

#9 22developer  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 65
  • Joined: 26-August 14

Re: Help with Java assignment

Posted 03 September 2014 - 04:09 PM

nothing's wrong with compiling it!
it should be your compilers problem.

This post has been edited by 22developer: 03 September 2014 - 04:19 PM

Was This Post Helpful? 0
  • +
  • -

#10 mike73  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 250
  • View blog
  • Posts: 918
  • Joined: 24-April 10

Re: Help with Java assignment

Posted 04 September 2014 - 03:49 PM

Just a wild guess, is there a sample input/output provided which you might have to match?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1