Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Day16C {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String txtIn;
- int arraySize=0;
- double numTotal=0;
- double[] numList;
- try {
- System.out.print("Enter total items to add:");
- txtIn = sc.nextLine();
- arraySize = Integer.parseInt(txtIn);
- } catch (Exception e) {
- System.out.println("error in array size");
- arraySize = 3;
- } finally {
- numList = new double[arraySize];
- System.out.printf("%nEnter %d numbers:",numList.length);
- }
- for (int i = 0; i < arraySize; i++) {
- try {
- System.out.printf("(%d):",i);
- txtIn = sc.nextLine();
- numList[i] = Double.parseDouble(txtIn);
- numTotal += numList[i];
- }catch (Exception e) {
- System.out.println("error in array size");
- arraySize = 3;
- }
- }
- }
- }
- //------------------------------------------
- import java.util.Scanner;
- public class Day16D {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String[][] txtArray = {
- {"r0c0","r0c1","r0c2"}
- ,{"r1c0","r1c1","r1c2"}
- ,{"r2c0","r2c1","r2c2"}
- };
- int row,column;
- String txtIn;
- try {
- System.out.print("row:");
- txtIn = sc.nextLine();
- row = Integer.parseInt(txtIn) - 1;
- System.out.print("col:");
- txtIn = sc.nextLine();
- column = Integer.parseInt(txtIn) - 1;
- System.out.printf("Content of row %d%n", row);
- for (int i = 0; i < txtArray[row].length; i++) {
- System.out.print(txtArray[row][i] + ",");
- }
- System.out.printf("%nContent of row %d, column %d: %s%n"
- , row,column, txtArray[row][column]);
- } catch (Exception e) {
- System.out.println("there is an error");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment