java

using scanner to get input, and while loop to make sure that the input

Page 1 of 1

3 Replies - 861 Views - Last Post: 17 April 2009 - 09:44 PM Rate Topic: -----

#1 adam.mac11m  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 17-April 09

java

Posted 17 April 2009 - 05:37 PM

I tried everything but with no success so can you help!
By using the Scanner to get the input
I need to use the while loop and make sure that the user enter number then the percentage symbol
For example 25%
Or decimal number for example . 23
Anything else is not acceptable input


package javaapplication61;
import java.util.Scanner;
import java.text.DecimalFormat;
public class Main
{

public static void main(String[] args)
{
String percentage;
System.out.println("Enter the percentage");
Scanner keyboard = new Scanner(System.in);
percentage = keyboard.next();
while (input != '. # '|| input != '#%')
{
System.out.println("enter the percentage Agin");
}
}
}

This post has been edited by adam.mac11m: 17 April 2009 - 05:58 PM


Is This A Good Question/Topic? 0
  • +

Replies To: java

#2 sbell1099  Icon User is offline

  • Inspiring StoryTeller
  • member icon

Reputation: 16
  • View blog
  • Posts: 685
  • Joined: 28-October 08

Re: java

Posted 17 April 2009 - 05:39 PM

[rules][/rules]
Was This Post Helpful? 1
  • +
  • -

#3 NeoTifa  Icon User is offline

  • NeoTifa Codebreaker, the Scourge of Devtester
  • member icon





Reputation: 4201
  • View blog
  • Posts: 18,434
  • Joined: 24-September 08

Re: java

Posted 17 April 2009 - 06:59 PM

Does it compile?
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

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

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: java

Posted 17 April 2009 - 09:44 PM

Your post transgress 2 rules of this forum that were shown to you when you posted your topic

Rule #4: :code:
Rule #5: Give your topic a descriptive title, NOT "Help" or "Plz Help Me" or "I'm a noob". Naming a topic "Java" in a forum devoted to Java is kind of useless

Go back and Edit (full edit) your post to add the [ code] tags and to change the title of your post for a more descriptive description

But for sure:

while (input != '. # '|| input != '#%')
what is input ?
seems to represent a char and a char is a single digit so can be '.' or '#' or '%' but cannot have a length of 2 like '.#' or '#%'

This post has been edited by pbl: 17 April 2009 - 09:47 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1