2 Replies - 1581 Views - Last Post: 06 June 2012 - 12:41 PM Rate Topic: -----

#1 zee5229   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 20
  • Joined: 29-March 12

switch case error:incompatible types; pls help

Posted 06 June 2012 - 12:36 PM

I am trying to make a program that prints out a number as a string of symbols that look like the numbers but for some reason my switch case won't compile. Any help would be greatly appreciated. Line 29 is where the incompatible types error is.

import java.io.*;
import java.util.*;
public class Big_Numbers
{
	public static void main(String zee[])throws IOException
	{
		Scanner input=new Scanner(new File("numbers.in"));
		String bigNumber=input.nextLine();

		int length=bigNumber.length();

		String numbers[]=new String[length];

		for(int i=0; i<length;i++ )
		{
			numbers[i]=bigNumber.substring(i, i+1);

			switch (numbers[i])
			{

				case 1: one();
					break;
				default: System.out.print("error: not a number");
					break;
			}
		}




	}//end of main method


     static void one()
     {
       System.out.print("   1");
       System.out.print("  11");
       System.out.print("   1");
       System.out.print("   1");
       System.out.print(" 11111");
     }

      static void two()
     {
     	System.out.print("22222");
     	System.out.print("    2");
     	System.out.print("22222");
     	System.out.print("2");
     	System.out.print("22222");
     }

      static void three()
     {
     	System.out.print("33333");
     	System.out.print("    3");
     	System.out.print("  333");
     	System.out.print("    3");
     	System.out.print("33333");
     }

     static void four()
     {
     	System.out.print("4   4");
     	System.out.print("4   4");
     	System.out.print("44444");
     	System.out.print("    4");
     	System.out.print("    4");
     }

     static void five()
     {
     	System.out.print("55555");
     	System.out.print("5");
     	System.out.print("55555");
     	System.out.print("    5");
     	System.out.print("55555");
     }

     static void six()
     {
     	System.out.print("66666");
     	System.out.print("6");
     	System.out.print("66666");
     	System.out.print("6   6");
     	System.out.print("66666");
     }

     static void seven()
     {
     	System.out.print("77777");
     	System.out.print("    7");
     	System.out.print("    7");
     	System.out.print("    7");
     	System.out.print("    7");
     }

     static void eight()
     {
     	System.out.print("88888");
     	System.out.print("8   8");
     	System.out.print("88888");
     	System.out.print("8   8");
     	System.out.print("88888");
     }

     static void nine()
     {
     	System.out.print("99999");
     	System.out.print("9   9");
     	System.out.print("99999");
     	System.out.print("    9");
     	System.out.print("99999");
     }

     static void zero()
     {
     	System.out.print("00000");
     	System.out.print("0   0");
     	System.out.print("0   0");
     	System.out.print("0   0");
     	System.out.print("00000");
     }



excuse me line 21 not 29

Is This A Good Question/Topic? 0
  • +

Replies To: switch case error:incompatible types; pls help

#2 pbl   User is offline

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

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

Re: switch case error:incompatible types; pls help

Posted 06 June 2012 - 12:40 PM

You need JRE 1.7 to switch on String
and your method one() is void so it is not a String
Switch are resolved at compile time, you cannot invoke a method in a case: clause
Was This Post Helpful? 1
  • +
  • -

#3 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12800
  • View blog
  • Posts: 45,992
  • Joined: 27-December 08

Re: switch case error:incompatible types; pls help

Posted 06 June 2012 - 12:41 PM

If you don't have Java 7 installed, you can only use ints, bytes, shorts, and chars on a switch.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1