There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
audio avg avg 8 blue screen brand new codec control panel conversion crash delete personal data desktop display dos driver duplicate dvd error error message excel explorer file firefox game graphics hardware hijackthis log install installation internet itunes javascript laptop macro malware monitor msconfig msn music network outlook outlook 2003 outlook express php problem program random rundll32 security seo sound sp3 spyware switch tag cloud trojan usb video virtumonde virus vista visual basic vundo wallpaper windows windows vista windows xp wireless word xp sp3 youtube
Software Development
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
Finals Help: Java


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
cc64's Avatar
Computer Specs
Member with 66 posts.
 
Join Date: Dec 2007
Experience: Fairly Knowledgeable
07-May-2008, 08:58 PM #1
Finals Help: Java
Hi all,
Just doing a little reviewing for finals in my CS class and I'm having a little trouble.

Here's the problem: Implement a method named isBig that will accept one string parameter named alpha. It will return true only if the length of the string is greater than 6.

Here's my answer:
Here is the method:
Code:
public boolean isBig(String alpha)
	{
		if (alpha.length() > 6)
			return true;
		else
			return false;
	}
Here is it running in main:
Code:
                String alpha;
		System.out.println("Enter a string: ");
		alpha = scan.nextLine();
		
		System.out.println(ob1.isBig(alpha));
And here is the output:
Quote:
Enter a string:
false
So I can't figure out why it isn't letting me input a String and just skipping right to the method part. It's probably something really simple and it's just going over my head. Any help is appreciated. Thanks

Curtis
__________________
Technology is dominated by two types of people: those who understand what they do not manage, and those who manage what they do not understand.
Chicon's Avatar
Computer Specs
Distinguished Member with 6,213 posts.
 
Join Date: Jul 2004
Location: 50° 34' 07.13" N - 04° 10' 23.58" E
Experience: Intermediate
08-May-2008, 01:17 AM #2
Hi Curtis,

Just check if your scanner instantiation is defined this way :
Scanner scan = new Scanner(System.in);
Also, check if you don't have a premature scan.close() statement in your coding.
Jackiefrost9's Avatar
Computer Specs
Distinguished Member with 3,720 posts.
 
Join Date: Jun 2004
Location: Spokane, Wa
Experience: Advanced
08-May-2008, 03:39 AM #3
Just so you know, you can shorten that method by just returning alpha.length() > 6.

return alpha.length() > 6;

It will evaluate the expression, which is either true or false, then return that.
That's called 'Boolean Zen'.
Reply

Tags
boolean, comparison, java, string


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 11:44 PM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.