Loop That Stops Printing A File And Adding To Stack
May 6, 2015
I'm supposed to add characters to a stack and pop them once the adjacent delimiter is read in from a text file. Moreover, program is supposed to print out the incoming text from the file, but stop when the applicable delimiter is not on top of the stack. As in, a '[' doesn't have a ']'.
I've got the program so it can pop and add to the stack correctly, and stops adding at the correct time, but I cant seem to get it to stop printing. I know a switch statement method in another class seems obvious, but I was trying to practice nested loops.
This is the main program:
import java.io.*;
import java.util.Scanner;
import java.io.IOException;
import java.util.Stack;
public class DelimiterChecker {
public static void main(String [] args) throws IOException {
[Code] ......
Moreover, the file I'm reading for is simply:
{
System.out.println(1)
System.out.println(2)
System.out.println(6 <-------------missing delimiter
System.out.println(7)
}
View Replies
Dec 5, 2014
I want to print each value in the multi-dimensional array using a for loop but there is a problem.
Here is the script:
Java Code:
public class LearningJava
{
public static void main(String[] args) {
int[][] Grid = {
{12, 24, 36, 48, 60},
{1, 3, 5},
[Code] ....
Printing i: 0, x: 12
Printing i: 0, x: 24
Exception in thread "main" Printing i: 0, x: 36
Printing i: 0, x: 48
Printing i: 0, x: 60
java.lang.ArrayIndexOutOfBoundsException: 5
at LearningJava.main(LearningJava.java:11)
It's suppose to get the length of each array and print all the values in that array and then move to the next one.
I tried adding .length
Java Code: for(int x = 0; x < Grid[i][x].length; x++) mh_sh_highlight_all('java');
but then it doesn't work at all.
View Replies
View Related
Apr 22, 2015
The thing my coding for sudoku is not working for few inputs... it works fine with all its value initially at 0, but when i place numbers more than 4 at random places it stops responding (it doesn't show any value).
My assignment is to get a solved sudoku for these values:
//Sample Input:
{0,2,7,3,8,0,0,1,0},
{0,1,0,0,0,6,7,3,5},
{0,0,0,0,0,0,0,2,9},
{3,0,5,6,9,2,0,8,0},
{0,0,0,0,0,0,0,0,0},
{0,6,0,1,7,4,5,0,3},
{6,4,0,0,0,0,0,0,0},
{9,5,1,8,0,0,0,7,0},
{0,8,0,0,6,5,3,4,0}
My Current code
public class Sudoku {
static int userGrid[][]=new int[][]
{{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0}};//[horizontal][vertical]
static int grid[][]=new int[9][9];//the grid that the program experiments on
public static void main(String[] args) {
[Code] ....
View Replies
View Related