I need to create a menu, and then depend on the choice, carry out a certain task. But sumhow any number i put in become sumthing else so the switch become deafualt. Can sum1 help?

import java.text.DecimalFormat;
import java.util.Scanner;

public class Lab0602_ATT
{
	public static void main (String args[])							
	{   
 		Scanner kb  = new Scanner(System.in);
		DecimalFormat output = new DecimalFormat("0000.000");
		int menu = 0;
		
		
		do
		{
		
		System.out.println("1.  Given the Diameter, Compute the Area and Circumference");
		System.out.println("2.	Compute Factorial");	
		System.out.println("3.	Fibonacci Sequence");	
		System.out.println("4.	GCF");	
		System.out.println("6.	Quit");
		System.out.print("Choose option    ");
		menu  = kb.nextInt();

			switch (menu)
			{
			case '1' :
				double area, circum = 0;
				System.out.println("Enter Diameter");
				int diameter  = kb.nextInt();
				area = Math.PI*Math.pow((diameter/2),2);
				circum = Math.PI*diameter;
				System.out.println("Area ="+area);
				System.out.println("Circumference ="+circum);
				break;
				
			case '2' :
				break;
			
			case '3' :
				break;
			
			case '4' :
				break;

			case '5' :
				break;
			
			case '6' :
				break;
			default : System.out.println("Wrong menu choice");
				
			} //switch


		}while (menu!=6);
	}//main
}//Lab0602

Recommended Answers

All 2 Replies

just need sum help on how to fix it so it can carry out the task if I enter 1

I havent tried your code yet but since you declare menu as int, I think you dont need to enclose it in single quiotes in the case statement. try removing those and see what happens.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.