|
yes. i know about that token. but up until now i still couldnnt find the source code for splitting it into token as i only interested for keyword "if", "else" and "switch case" only.
where can i find the suitable code for that task?
|
|
|
|
|
Shakirin Mohd Amin wrote: where can i find the suitable code for that task?
You have to write it!
|
|
|
|
|
yes. that is it. my problem now is i couldn't find source code to read the source file & yet count the "if" & "switch" statement. this things make me stuck here ;(
|
|
|
|
|
how will I make my own mine sweeper game application using NetBeans?
|
|
|
|
|
See here[^] for Java samples which may help you.
|
|
|
|
|
|
I did try to use the codes but nothings work...did anybody get it right?????can anybody gonna help me???thanx
|
|
|
|
|
|
Hello. I did this..
package javaapplication6;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try{
System.out.println("Enter number of rows");
int m = Integer.parseInt(br.readLine());
System.out.println("Enter number of columns");
int n = Integer.parseInt(br.readLine());
int[][] first = new int[m][n];
int[][] second = new int[m][n];
int[][] sum = new int[m][n];
System.out.println("Enter Value of first matrix");
{
for (int i=0;i<m;m++)
{
for (int j=0; j<n;j++)
{
first[m][n] = Integer.parseInt(br.readLine());
}
}
}
System.out.println("Enter value of second matrix");
{
for (int i=0;i<m;m++)
{
System.out.println("Row no. " + (i+1));
for (int j=0;j<n;j++)
{
System.out.println("Enter value for column no. " + (j+1));
second[m][n] = Integer.parseInt(br.readLine());
}
}
}
System.out.println("Sum of two matrices are:");
{
for (int i=0;i<m;i++)
{
for (int j = 0; j<n;j++)
{
sum[m][n] = first[m][n] + second[m][n];
}
}
System.out.println(sum[m][n]);
}
}
catch (IOException e)
{
System.out.println(e);
}
}
}
Here in bold text..
first[m][n] = Integer.parseInt(br.readLine());
throws ArrayIndexOutOfBoundexception ....
When I replace first[m][n] with first[i][j] .. it taking value ..
how to rectify this error any suggestion..
|
|
|
|
|
nt_virus wrote: how to rectify this error any suggestion.
I think this statement for (int i=0;i<m;m++) has a slight error.
|
|
|
|
|
but that line add column values for 2nd row and so on till
|
|
|
|
|
nt_virus wrote: but that line add column values for 2nd row and so on till
Look closely, at the end of the loop you are incrementing the wrong variable
|
|
|
|
|
poor me...
I modified as following ,, and I m done around 90%
package javaapplication6;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try{
System.out.println("Enter number of rows");
int m = Integer.parseInt(br.readLine());
System.out.println("Enter number of columns");
int n = Integer.parseInt(br.readLine());
int[][] first = new int[m][n];
int[][] second = new int[m][n];
int[][] sum = new int[m][n];
System.out.println("Enter Value of first matrix");
{
for (int i=0;i<first.length;i++)
{
System.out.println("Row no. " + (i+1));
for (int j=0; j<first[i].length;j++)
{
System.out.println("Enter value for column no. " + (j+1));
first[i][j] = Integer.parseInt(br.readLine());
}
}
}
System.out.println("Enter value of second matrix");
{
for (int i=0;i<second.length;i++)
{
System.out.println("Row no. " + (i+1));
for (int j=0;j<second[i].length;j++)
{
System.out.println("Enter value for column no. " + (j+1));
second[i][j] = Integer.parseInt(br.readLine());
}
}
}
System.out.println("Sum of two matrices are:");
{
for (int i=0;i<first.length;i++)
{
for (int j = 0; j<second.length;j++)
{
sum[m][n] = first[i][j] + second[i][j];
}
}
System.out.println(sum[m][n]);
}
}
catch (IOException e)
{
System.out.println(e);
}
}
}
same error is showing when i m adding two arrays..
|
|
|
|
|
nt_virus wrote: sum[m][n] = first[i][j] + second[i][j];
Sorry but I stupidly missed this first time round, but you are using the wrong indices again. sum[m][n] is an array of size m by n, so the highest cell that can be addressed is sum[m-1][n-1] . Change it to sum[i][j] and I think it should work.
|
|
|
|
|
We both post posted at the same time. haha.
|
|
|
|
|
99% done..
for (int i=0;i<first.length;i++)
{
for (int j = 0; j<second.length;j++)
{
sum[i][j] = first[i][j] + second[i][j];
System.out.println(sum[i][j]);
}
But result are showing in vertical manner.. not like matrix way..
|
|
|
|
|
nt_virus wrote: But result are showing in vertical manner.. not like matrix way..
I can never remember what the order is supposed to be (I stick to one-dmensional arrays), so I'm afraid you will have to find it by trial and error. I would give you a hand but my Java system is not usable today.
|
|
|
|
|
please do it in c# if you can, I will convert. I did my all possible things.
|
|
|
|
|
OK, but it may take some time.
|
|
|
|
|
yes, no problem. do you use messenger ?
|
|
|
|
|
OK, I got the answer in C#, so I think the Java code needs to be:
for (int i=0;i < first.length;i++)
{
for (int j = 0; j < first[i].length;j++)
{
sum[i][j] = first[i][j] + second[i][j];
System.out.print(sum[i][j] + " ");
}
System.out.println("");
}
I'm not sure about the expression first.length , but basically i needs to iterate the rows, and j the columns. You also need to print each column value without the newline (print rather than println ?) and then put the System.out.println(""); statement after the last column. It probably needs some tidying up to get the columns lined up, but I'm sure you will be able to manage it.
No, not on messenger.
|
|
|
|
|
fantastic.. It works.. you made my day (night here actually) ..
Thanks a lot.
|
|
|
|
|
Cheers, happy to help. It also gave me some incentive to get back on Java which I haven't touched for a while.
It's early evening here (UK) so are you west or east?
|
|
|
|
|
Java is very nice.
I m on east. India. +5.30
|
|
|
|
|
You may find this hard to believe but that's the country of my birth! I was born in Mussoorie (in the hills), my dad and my brother in Naini Tal.
But my only return visit was in 2005 to Bangalore, which also was nice - at least the people.
|
|
|
|