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 6 of 6

Thread: I'm starting on java development. Why is this error happening?

  1. #1
    Junior Member
    Join Date
    Oct 2020
    Location
    GB
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Unhappy I'm starting on java development. Why is this error happening?

    I made a program to print big numbers using the scanner to select those numbers, but I'm getting an error every time I try to compile it
    import java.util.*;
    public class Numbers{
    	public static void main(String[] args){
    		int num1, num2, num3, num4, num5, num6, num7, num8, num9, num10, quantity;
    		Scanner sc = new Scanner(System.in);
    		String[][]/*[Y][X]*/ bigNums = {
    			{	/*bigNums[0][0]*/ "           ",
    				/*bigNums[0][1]*/ "           ",
    				/*bigNums[0][2]*/ " ,pPYq.  ",
    				/*bigNums[0][3]*/ "6W'    `Wb ",
    				/*bigNums[0][4]*/ "8M      M8 ",
    				/*bigNums[0][5]*/ "YA.    ,A9 ",
    				/*bigNums[0][6]*/ " `Ybmmd9  "},
     
    			{	/*bigNums[1][0]*/ "       ",
    				/*bigNums[1][1]*/ " __,   ",
    				/*bigNums[1][2]*/ "`7MM   ",
    				/*bigNums[1][3]*/ "  MM   ",
    				/*bigNums[1][4]*/ "  MM   ",
    				/*bigNums[1][5]*/ "  MM   ",
    				/*bigNums[1][6]*/ ".JMML. "},
     
    			{	/*bigNums[2][0]*/ "         ",
    				/*bigNums[2][1]*/ "         ",
    				/*bigNums[2][2]*/ " pd**b. ",
    				/*bigNums[2][3]*/ "(O)   j8 ",
    				/*bigNums[2][4]*/ "    ,;j9 ",
    				/*bigNums[2][5]*/ " ,-=    ",
    				/*bigNums[2][6]*/ "Ammmmmmm "},
     
    			{	/*bigNums[3][0]*/ " pdb.  ",
    				/*bigNums[3][1]*/ "(O)  `8b ",
    				/*bigNums[3][2]*/ "     ,89 ",
    				/*bigNums[3][3]*/ "   Yb. ",
    				/*bigNums[3][4]*/ "      88 ",
    				/*bigNums[3][5]*/ "(O)  .M ",
    				/*bigNums[3][6]*/ " bmmmd  "},
     
    			{	/*bigNums[4][0]*/ "     ,AM   ",
    				/*bigNums[4][1]*/ "    AVMM   ",
    				/*bigNums[4][2]*/ "  ,W MM   ",
    				/*bigNums[4][3]*/ ",W   MM   ",
    				/*bigNums[4][4]*/ "AmmmmmMMmm ",
    				/*bigNums[4][5]*/ "      MM   ",
    				/*bigNums[4][6]*/ "      MM   "},
     
    			{	/*bigNums[5][0]*/ " M****** ",
    				/*bigNums[5][1]*/ ".M       ",
    				/*bigNums[5][2]*/ "|bMMAg.  ",
    				/*bigNums[5][3]*/ "     `Mb ",
    				/*bigNums[5][4]*/ "      jM ",
    				/*bigNums[5][5]*/ "(O)  ,M9 ",
    				/*bigNums[5][6]*/ " 6mmm9   "},
     
    			{	/*bigNums[6][0]*/ "   .6*   ",
    				/*bigNums[6][1]*/ " ,M      ",
    				/*bigNums[6][2]*/ ",Mbmmm.   ",
    				/*bigNums[6][3]*/ "6M'  `Mb. ",
    				/*bigNums[6][4]*/ "MI     M8 ",
    				/*bigNums[6][5]*/ "WM.   ,M9 ",
    				/*bigNums[6][6]*/ " WMbmmd9  "},
     
    			{	/*bigNums[7][0]*/ "M******A ",
    				/*bigNums[7][1]*/ "Y     A  ",
    				/*bigNums[7][2]*/ "     A   ",
    				/*bigNums[7][3]*/ "    A    ",
    				/*bigNums[7][4]*/ "   A     ",
    				/*bigNums[7][5]*/ "  A      ",
    				/*bigNums[7][6]*/ " A       "},
     
    			{	/*bigNums[8][0]*/ " ,6**VA. ",
    				/*bigNums[8][1]*/ "dN     V8 ",
    				/*bigNums[8][2]*/ "`MN.  ,g9 ",
    				/*bigNums[8][3]*/ " ,MMMMq.  ",
    				/*bigNums[8][4]*/ "6P   `YMb ",
    				/*bigNums[8][5]*/ "8b    `M9 ",
    				/*bigNums[8][6]*/ "`MmmmmM9  "},
     
    			{	/*bigNums[9][0]*/ " .d**bg. ",
    				/*bigNums[9][1]*/ "6MP    Mb ",
    				/*bigNums[9][2]*/ "YMb    MM ",
    				/*bigNums[9][3]*/ " `MbmmdM9 ",
    				/*bigNums[9][4]*/ "      .M ",
    				/*bigNums[9][5]*/ "    .d9   ",
    				/*bigNums[9][6]*/ "  m     "}
    		};
    		System.out.println("quantity of digits: (max 10, 0 is invalid)");
    		quantity = sc.nextInt();
    		System.out.println("enter the digits backwards (starting with the last one, for example for");
    		System.out.println("1533 enter 3, 3, 5 and 1 in that order)");
    		switch(quantity){
    			case 10:
    				System.out.println("tenth digit");
    				num10 = sc.nextInt();
    			case 9:
    				System.out.println("nineth digit");
    				num9 = sc.nextInt();
    			case 8:
    				System.out.println("eighth digit");
    				num8 = sc.nextInt();
    			case 7:
    				System.out.println("seventh digit");
    				num7 = sc.nextInt();
    			case 6:
    				System.out.println("sixth digit");
    				num6 = sc.nextInt();
    			case 5:
    				System.out.println("fifth digit");
    				num5 = sc.nextInt();
    			case 4:
    				System.out.println("fourth digit");
    				num4 = sc.nextInt();
    			case 3:
    				System.out.println("third digit");
    				num3 = sc.nextInt();
    			case 2:
    				System.out.println("second digit");
    				num2 = sc.nextInt();
    			case 1:
    				System.out.println("first digit");
    				num1 = sc.nextInt();
    			break;
    			default:
    				System.out.println("invalid quantity");
    			break;
    		}
    		switch(quantity){
    			case 1:
    				System.out.println(bigNums[num1][0]);
    				System.out.println(bigNums[num1][1]);
    				System.out.println(bigNums[num1][2]);
    				System.out.println(bigNums[num1][3]);
    				System.out.println(bigNums[num1][4]);
    				System.out.println(bigNums[num1][5]);
    				System.out.println(bigNums[num1][6]);
    			break;
    			case 2:
    				System.out.println(bigNums[num1][0] + bigNums[num2][0]);
    				System.out.println(bigNums[num1][1] + bigNums[num2][1]);
    				System.out.println(bigNums[num1][2] + bigNums[num2][2]);
    				System.out.println(bigNums[num1][3] + bigNums[num2][3]);
    				System.out.println(bigNums[num1][4] + bigNums[num2][4]);
    				System.out.println(bigNums[num1][5] + bigNums[num2][5]);
    				System.out.println(bigNums[num1][6] + bigNums[num2][6]);
    			break;
    			case 3:
    				System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0]);
    				System.out.println(bigNums[num1][1] + bigNums[num2][1] + bigNums[num3][1]);
    				System.out.println(bigNums[num1][2] + bigNums[num2][2] + bigNums[num3][2]);
    				System.out.println(bigNums[num1][3] + bigNums[num2][3] + bigNums[num3][3]);
    				System.out.println(bigNums[num1][4] + bigNums[num2][4] + bigNums[num3][4]);
    				System.out.println(bigNums[num1][5] + bigNums[num2][5] + bigNums[num3][5]);
    				System.out.println(bigNums[num1][6] + bigNums[num2][6] + bigNums[num3][6]);
    			break;
    			case 4:
    				System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0]);
    				System.out.println(bigNums[num1][1] + bigNums[num2][1] + bigNums[num3][1] + bigNums[num4][1]);
    				System.out.println(bigNums[num1][2] + bigNums[num2][2] + bigNums[num3][2] + bigNums[num4][2]);
    				System.out.println(bigNums[num1][3] + bigNums[num2][3] + bigNums[num3][3] + bigNums[num4][3]);
    				System.out.println(bigNums[num1][4] + bigNums[num2][4] + bigNums[num3][4] + bigNums[num4][4]);
    				System.out.println(bigNums[num1][5] + bigNums[num2][5] + bigNums[num3][5] + bigNums[num4][5]);
    				System.out.println(bigNums[num1][6] + bigNums[num2][6] + bigNums[num3][6] + bigNums[num4][6]);
    			break;
    			case 5:
    				System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0]);
    				System.out.println(bigNums[num1][1] + bigNums[num2][1] + bigNums[num3][1] + bigNums[num4][1] + bigNums[num5][1]);
    				System.out.println(bigNums[num1][2] + bigNums[num2][2] + bigNums[num3][2] + bigNums[num4][2] + bigNums[num5][2]);
    				System.out.println(bigNums[num1][3] + bigNums[num2][3] + bigNums[num3][3] + bigNums[num4][3] + bigNums[num5][3]);
    				System.out.println(bigNums[num1][4] + bigNums[num2][4] + bigNums[num3][4] + bigNums[num4][4] + bigNums[num5][4]);
    				System.out.println(bigNums[num1][5] + bigNums[num2][5] + bigNums[num3][5] + bigNums[num4][5] + bigNums[num5][5]);
    				System.out.println(bigNums[num1][6] + bigNums[num2][6] + bigNums[num3][6] + bigNums[num4][6] + bigNums[num5][6]);
    			break;
    			case 6:
    				System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0]);
    				System.out.println(bigNums[num1][1] + bigNums[num2][1] + bigNums[num3][1] + bigNums[num4][1] + bigNums[num5][1] + bigNums[num6][1]);
    				System.out.println(bigNums[num1][2] + bigNums[num2][2] + bigNums[num3][2] + bigNums[num4][2] + bigNums[num5][2] + bigNums[num6][2]);
    				System.out.println(bigNums[num1][3] + bigNums[num2][3] + bigNums[num3][3] + bigNums[num4][3] + bigNums[num5][3] + bigNums[num6][3]);
    				System.out.println(bigNums[num1][4] + bigNums[num2][4] + bigNums[num3][4] + bigNums[num4][4] + bigNums[num5][4] + bigNums[num6][4]);
    				System.out.println(bigNums[num1][5] + bigNums[num2][5] + bigNums[num3][5] + bigNums[num4][5] + bigNums[num5][5] + bigNums[num6][5]);
    				System.out.println(bigNums[num1][6] + bigNums[num2][6] + bigNums[num3][6] + bigNums[num4][6] + bigNums[num5][6] + bigNums[num6][6]);
    			break;
    			case 7:
    				System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0] + bigNums[num7][0]);
    				System.out.println(bigNums[num1][1] + bigNums[num2][1] + bigNums[num3][1] + bigNums[num4][1] + bigNums[num5][1] + bigNums[num6][1] + bigNums[num7][1]);
    				System.out.println(bigNums[num1][2] + bigNums[num2][2] + bigNums[num3][2] + bigNums[num4][2] + bigNums[num5][2] + bigNums[num6][2] + bigNums[num7][2]);
    				System.out.println(bigNums[num1][3] + bigNums[num2][3] + bigNums[num3][3] + bigNums[num4][3] + bigNums[num5][3] + bigNums[num6][3] + bigNums[num7][3]);
    				System.out.println(bigNums[num1][4] + bigNums[num2][4] + bigNums[num3][4] + bigNums[num4][4] + bigNums[num5][4] + bigNums[num6][4] + bigNums[num7][4]);
    				System.out.println(bigNums[num1][5] + bigNums[num2][5] + bigNums[num3][5] + bigNums[num4][5] + bigNums[num5][5] + bigNums[num6][5] + bigNums[num7][5]);
    				System.out.println(bigNums[num1][6] + bigNums[num2][6] + bigNums[num3][6] + bigNums[num4][6] + bigNums[num5][6] + bigNums[num6][6] + bigNums[num7][6]);
    			break;
    			case 8:
    				System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0] + bigNums[num7][0] + bigNums[num8][0]);
    				System.out.println(bigNums[num1][1] + bigNums[num2][1] + bigNums[num3][1] + bigNums[num4][1] + bigNums[num5][1] + bigNums[num6][1] + bigNums[num7][1] + bigNums[num8][1]);
    				System.out.println(bigNums[num1][2] + bigNums[num2][2] + bigNums[num3][2] + bigNums[num4][2] + bigNums[num5][2] + bigNums[num6][2] + bigNums[num7][2] + bigNums[num8][2]);
    				System.out.println(bigNums[num1][3] + bigNums[num2][3] + bigNums[num3][3] + bigNums[num4][3] + bigNums[num5][3] + bigNums[num6][3] + bigNums[num7][3] + bigNums[num8][3]);
    				System.out.println(bigNums[num1][4] + bigNums[num2][4] + bigNums[num3][4] + bigNums[num4][4] + bigNums[num5][4] + bigNums[num6][4] + bigNums[num7][4] + bigNums[num8][4]);
    				System.out.println(bigNums[num1][5] + bigNums[num2][5] + bigNums[num3][5] + bigNums[num4][5] + bigNums[num5][5] + bigNums[num6][5] + bigNums[num7][5] + bigNums[num8][5]);
    				System.out.println(bigNums[num1][6] + bigNums[num2][6] + bigNums[num3][6] + bigNums[num4][6] + bigNums[num5][6] + bigNums[num6][6] + bigNums[num7][6] + bigNums[num8][6]);
    			break;
    			case 9:
    				System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0] + bigNums[num7][0] + bigNums[num8][0] + bigNums[num9][0]);
    				System.out.println(bigNums[num1][1] + bigNums[num2][1] + bigNums[num3][1] + bigNums[num4][1] + bigNums[num5][1] + bigNums[num6][1] + bigNums[num7][1] + bigNums[num8][1] + bigNums[num9][1]);
    				System.out.println(bigNums[num1][2] + bigNums[num2][2] + bigNums[num3][2] + bigNums[num4][2] + bigNums[num5][2] + bigNums[num6][2] + bigNums[num7][2] + bigNums[num8][2] + bigNums[num9][2]);
    				System.out.println(bigNums[num1][3] + bigNums[num2][3] + bigNums[num3][3] + bigNums[num4][3] + bigNums[num5][3] + bigNums[num6][3] + bigNums[num7][3] + bigNums[num8][3] + bigNums[num9][3]);
    				System.out.println(bigNums[num1][4] + bigNums[num2][4] + bigNums[num3][4] + bigNums[num4][4] + bigNums[num5][4] + bigNums[num6][4] + bigNums[num7][4] + bigNums[num8][4] + bigNums[num9][4]);
    				System.out.println(bigNums[num1][5] + bigNums[num2][5] + bigNums[num3][5] + bigNums[num4][5] + bigNums[num5][5] + bigNums[num6][5] + bigNums[num7][5] + bigNums[num8][5] + bigNums[num9][5]);
    				System.out.println(bigNums[num1][6] + bigNums[num2][6] + bigNums[num3][6] + bigNums[num4][6] + bigNums[num5][6] + bigNums[num6][6] + bigNums[num7][6] + bigNums[num8][6] + bigNums[num9][6]);
    			break;
    			case 10:
    				System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0] + bigNums[num7][0] + bigNums[num8][0] + bigNums[num9][0] + bigNums[num10][0]);
    				System.out.println(bigNums[num1][1] + bigNums[num2][1] + bigNums[num3][1] + bigNums[num4][1] + bigNums[num5][1] + bigNums[num6][1] + bigNums[num7][1] + bigNums[num8][1] + bigNums[num9][1] + bigNums[num10][1]);
    				System.out.println(bigNums[num1][2] + bigNums[num2][2] + bigNums[num3][2] + bigNums[num4][2] + bigNums[num5][2] + bigNums[num6][2] + bigNums[num7][2] + bigNums[num8][2] + bigNums[num9][2] + bigNums[num10][2]);
    				System.out.println(bigNums[num1][3] + bigNums[num2][3] + bigNums[num3][3] + bigNums[num4][3] + bigNums[num5][3] + bigNums[num6][3] + bigNums[num7][3] + bigNums[num8][3] + bigNums[num9][3] + bigNums[num10][3]);
    				System.out.println(bigNums[num1][4] + bigNums[num2][4] + bigNums[num3][4] + bigNums[num4][4] + bigNums[num5][4] + bigNums[num6][4] + bigNums[num7][4] + bigNums[num8][4] + bigNums[num9][4] + bigNums[num10][4]);
    				System.out.println(bigNums[num1][5] + bigNums[num2][5] + bigNums[num3][5] + bigNums[num4][5] + bigNums[num5][5] + bigNums[num6][5] + bigNums[num7][5] + bigNums[num8][5] + bigNums[num9][5] + bigNums[num10][5]);
    				System.out.println(bigNums[num1][6] + bigNums[num2][6] + bigNums[num3][6] + bigNums[num4][6] + bigNums[num5][6] + bigNums[num6][6] + bigNums[num7][6] + bigNums[num8][6] + bigNums[num9][6] + bigNums[num10][6]);
    			break;
    		}
    	}
    }
    When I try to compile this program, the cmd promt outputs this:
    Numbers.java:148: error: variable num1 might not have been initialized
                                    System.out.println(bigNums[num1][0]);
                                                               ^
    Numbers.java:158: error: variable num1 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0]);
                                                               ^
    Numbers.java:158: error: variable num2 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0]);
                                                                                  ^
    Numbers.java:168: error: variable num1 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0]);
                                                               ^
    Numbers.java:168: error: variable num2 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0]);
                                                                                  ^
    Numbers.java:168: error: variable num3 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0]);
                                                                                                     ^
    Numbers.java:178: error: variable num1 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0]);
                                                               ^
    Numbers.java:178: error: variable num2 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0]);
                                                                                  ^
    Numbers.java:178: error: variable num3 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0]);
                                                                                                     ^
    Numbers.java:178: error: variable num4 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0]);
                                                                                                                        ^
    Numbers.java:188: error: variable num1 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0]);
                                                               ^
    Numbers.java:188: error: variable num2 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0]);
                                                                                  ^
    Numbers.java:188: error: variable num3 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0]);
                                                                                                     ^
    Numbers.java:188: error: variable num4 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0]);
                                                                                                                        ^
    Numbers.java:188: error: variable num5 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0]);
                                                                                                                                           ^
    Numbers.java:198: error: variable num1 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0]);
                                                               ^
    Numbers.java:198: error: variable num2 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0]);
                                                                                  ^
    Numbers.java:198: error: variable num3 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0]);
                                                                                                     ^
    Numbers.java:198: error: variable num4 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0]);
                                                                                                                        ^
    Numbers.java:198: error: variable num5 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0]);
                                                                                                                                           ^
    Numbers.java:198: error: variable num6 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0]);
                                                                                                                                                              ^
    Numbers.java:208: error: variable num1 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0] + bigNums[num7][0]);
                                                               ^
    Numbers.java:208: error: variable num2 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0] + bigNums[num7][0]);
                                                                                  ^
    Numbers.java:208: error: variable num3 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0] + bigNums[num7][0]);
                                                                                                     ^
    Numbers.java:208: error: variable num4 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0] + bigNums[num7][0]);
                                                                                                                        ^
    Numbers.java:208: error: variable num5 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0] + bigNums[num7][0]);
                                                                                                                                           ^
    Numbers.java:208: error: variable num6 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0] + bigNums[num7][0]);
                                                                                                                                                              ^
    Numbers.java:208: error: variable num7 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0] + bigNums[num7][0]);
                                                                                                                                                                                 ^
    Numbers.java:218: error: variable num1 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0] + bigNums[num7][0] + bigNums[num8][0]);
                                                               ^
    Numbers.java:218: error: variable num2 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0] + bigNums[num7][0] + bigNums[num8][0]);
                                                                                  ^
    Numbers.java:218: error: variable num3 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0] + bigNums[num7][0] + bigNums[num8][0]);
                                                                                                     ^
    Numbers.java:218: error: variable num4 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0] + bigNums[num7][0] + bigNums[num8][0]);
                                                                                                                        ^
    Numbers.java:218: error: variable num5 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0] + bigNums[num7][0] + bigNums[num8][0]);
                                                                                                                                           ^
    Numbers.java:218: error: variable num6 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0] + bigNums[num7][0] + bigNums[num8][0]);
                                                                                                                                                              ^
    Numbers.java:218: error: variable num7 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0] + bigNums[num7][0] + bigNums[num8][0]);
                                                                                                                                                                                 ^
    Numbers.java:218: error: variable num8 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0] + bigNums[num7][0] + bigNums[num8][0]);
                                                                                                                                                                                                    ^
    Numbers.java:228: error: variable num1 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0] + bigNums[num7][0] + bigNums[num8][0] + bigNums[num9][0]);
                                                               ^
    Numbers.java:228: error: variable num2 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0] + bigNums[num7][0] + bigNums[num8][0] + bigNums[num9][0]);
                                                                                  ^
    Numbers.java:228: error: variable num3 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0] + bigNums[num7][0] + bigNums[num8][0] + bigNums[num9][0]);
                                                                                                     ^
    Numbers.java:228: error: variable num4 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0] + bigNums[num7][0] + bigNums[num8][0] + bigNums[num9][0]);
                                                                                                                        ^
    Numbers.java:228: error: variable num5 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0] + bigNums[num7][0] + bigNums[num8][0] + bigNums[num9][0]);
                                                                                                                                           ^
    Numbers.java:228: error: variable num6 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0] + bigNums[num7][0] + bigNums[num8][0] + bigNums[num9][0]);
                                                                                                                                                              ^
    Numbers.java:228: error: variable num7 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0] + bigNums[num7][0] + bigNums[num8][0] + bigNums[num9][0]);
                                                                                                                                                                                 ^
    Numbers.java:228: error: variable num8 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0] + bigNums[num7][0] + bigNums[num8][0] + bigNums[num9][0]);
                                                                                                                                                                                                    ^
    Numbers.java:228: error: variable num9 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0] + bigNums[num7][0] + bigNums[num8][0] + bigNums[num9][0]);
                                                                                                                                                                                                                       ^
    Numbers.java:238: error: variable num1 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0] + bigNums[num7][0] + bigNums[num8][0] + bigNums[num9][0] + bigNums[num10][0]);
                                                               ^
    Numbers.java:238: error: variable num2 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0] + bigNums[num7][0] + bigNums[num8][0] + bigNums[num9][0] + bigNums[num10][0]);
                                                                                  ^
    Numbers.java:238: error: variable num3 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0] + bigNums[num7][0] + bigNums[num8][0] + bigNums[num9][0] + bigNums[num10][0]);
                                                                                                     ^
    Numbers.java:238: error: variable num4 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0] + bigNums[num7][0] + bigNums[num8][0] + bigNums[num9][0] + bigNums[num10][0]);
                                                                                                                        ^
    Numbers.java:238: error: variable num5 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0] + bigNums[num7][0] + bigNums[num8][0] + bigNums[num9][0] + bigNums[num10][0]);
                                                                                                                                           ^
    Numbers.java:238: error: variable num6 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0] + bigNums[num7][0] + bigNums[num8][0] + bigNums[num9][0] + bigNums[num10][0]);
                                                                                                                                                              ^
    Numbers.java:238: error: variable num7 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0] + bigNums[num7][0] + bigNums[num8][0] + bigNums[num9][0] + bigNums[num10][0]);
                                                                                                                                                                                 ^
    Numbers.java:238: error: variable num8 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0] + bigNums[num7][0] + bigNums[num8][0] + bigNums[num9][0] + bigNums[num10][0]);
                                                                                                                                                                                                    ^
    Numbers.java:238: error: variable num9 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0] + bigNums[num7][0] + bigNums[num8][0] + bigNums[num9][0] + bigNums[num10][0]);
                                                                                                                                                                                                                       ^
    Numbers.java:238: error: variable num10 might not have been initialized
                                    System.out.println(bigNums[num1][0] + bigNums[num2][0] + bigNums[num3][0] + bigNums[num4][0] + bigNums[num5][0] + bigNums[num6][0] + bigNums[num7][0] + bigNums[num8][0] + bigNums[num9][0] + bigNums[num10][0]);
                                                                                                                                                                                                                                          ^
    55 errors
    It says that the variables num1, num2, num3... num10 weren't initializated but I don't understand why
    Last edited by pansito; October 18th, 2020 at 06:00 PM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: I'm starting on java development. Why is this error happening?

    error: variable num1 might not have been initialized
    The compiler can not find in the code what the variable mentioned in the error message has been assigned a value.

    Make sure variables are assigned a value before using them.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Oct 2020
    Location
    GB
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: I'm starting on java development. Why is this error happening?

    The value of that specific variable is assigned here:
    /*line 137*/ System.out.println("first digit");
    /*line 138*/ num1 = sc.nextInt();
    As well as all the other variables on the other cases of the switch. I know what error is this but I can't understand why it happens

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: I'm starting on java development. Why is this error happening?

    The variables shown in the error messages are those above the ^ character.
    Assign values to all those variables where they are declared.


    /*line 138*/ num1 = sc.nextInt();
    That statement is in a switch statement and may not be executed.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Oct 2020
    Location
    GB
    Posts
    10
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: I'm starting on java development. Why is this error happening?

    Quote Originally Posted by Norm View Post
    It looks like all those variables are inside comments (within /* to */).
    No they aren't. The only comments are the positions of the strings in the arrays

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: I'm starting on java development. Why is this error happening?

    The variables shown in the error messages are those above the ^ character.
    Assign values to all those variables where they are declared.


    /*line 138*/ num1 = sc.nextInt();
    That statement is in a switch statement and may not be executed.
    If you don't understand my answer, don't ignore it, ask a question.

  7. The Following User Says Thank You to Norm For This Useful Post:

    pansito (October 18th, 2020)

Similar Threads

  1. [SOLVED] I'm starting on java development. What is wrong on this calculator?
    By pansito in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 13th, 2020, 07:51 AM
  2. Eclipse and WinRun4J - 'error starting Java VM'
    By schlinzj in forum Java IDEs
    Replies: 1
    Last Post: June 30th, 2014, 08:24 AM
  3. I am getting error while starting a websphere server
    By sachinspate in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 2nd, 2013, 08:19 AM
  4. Starting Android Application Development
    By MikeSki3 in forum Android Development
    Replies: 8
    Last Post: May 3rd, 2013, 07:54 AM
  5. Starting BlackBerry development
    By AttilioCarotenuto in forum Java ME (Mobile Edition)
    Replies: 1
    Last Post: July 29th, 2011, 12:11 PM