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;
		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);
			case '2' :
			case '3' :
			case '4' :

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

		}while (menu!=6);

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.

This article has been dead for over six months. Start a new discussion instead.