char cArr[10]; int iArr[20][10]; cArr[2] = 'x'; iArr[5][6] = 1;write
char *cArr = new char[10]; int **iArr = new int*[20]; for (int r = 0; r < 20; r++) iArr[r] = new int[10]; cArr[2] = 'x'; iArr[5][6] = 1;
int total = 0; for (int i = 0; i < 10; i++) total += i; i = 0;Note that the scope of i is the point of declaration to the end of the block the for statement is in. The C++ standard says the scope should be just the for loop itself; this is how g++ works. You cannot fix the above code by redeclaring i after the loop because then VC++ will complain that i is redeclared. We suggest that you write code to the C++ standard and then fix it when VC++ complains by using different variable names. "Compile Error" results stemming from this issue will count in the overall scoring. You have been warned.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
public class Input
{
public static void main(String[] args) throws IOException
{
BufferedReader stdin
= new BufferedReader(new InputStreamReader(System.in));
String input;
while ((input = stdin.readLine()) != null)
{
// input is a complete line of input
// do with it whatever it is you need to do
}
}
}
To read more than one thing on a line, you can read the entire line into a String with readLine as above and then use a StringTokenizer object to break the string apart. For example, the following code reads two integers given on the same line from standard input and outputs their product.
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.StringTokenizer;
public class Multiply
{
public static void main(String[] args) throws IOException
{
BufferedReader stdin
= new BufferedReader(new InputStreamReader(System.in));
String input = stdin.readLine();
StringTokenizer tok = new StringTokenizer(input);
int left = Integer.parseInt(tok.nextToken());
int right = Integer.parseInt(tok.nextToken());
System.out.println(left * right);
}
}