Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: switch and math problem issues

  1. #1
    Junior Member
    Join Date
    Jan 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default switch and math problem issues

    I'm new to java and have a project that requires me to make a math quiz for an individual. its starts be having the individual choose between: addition(+), sub(-), mult, and div(/). from there there determine whether the user wants random integers of 1 or 2 decimal places.
    Not sure how to use the switch in this case, please help.


  2. #2
    Senile Half-Wit Freaky Chris's Avatar
    Join Date
    Mar 2009
    Posts
    834
    My Mood
    Cynical
    Thanks
    7
    Thanked 105 Times in 90 Posts

    Default Re: switch and math problem issues

    Perhaps something like this.

    import java.util.Scanner;
     
    public class ReadChar {
    	public static void main(String[] args) {
    		Scanner s = new Scanner(System.in);
    		int decimal;
    		switch (s.next().charAt(0)) {
    			case '/':
    			case '*':
    				decimal = 2;
    				break;
    			default:
    				decimal = 1;
    				break;
    		}
    	}
    }

Similar Threads

  1. Having Issues Past this
    By baGoGoodies111 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 12th, 2009, 08:19 PM
  2. Question on my math
    By SwEeTAcTioN in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 25th, 2009, 05:42 PM
  3. Replies: 0
    Last Post: October 2nd, 2009, 10:51 PM
  4. Maven Issues - mvn install
    By Paolo Futre in forum Java Theory & Questions
    Replies: 5
    Last Post: August 26th, 2009, 05:07 AM
  5. Problem with sprite rotation in graphics
    By Katotetu in forum Algorithms & Recursion
    Replies: 0
    Last Post: May 8th, 2009, 07:27 PM