CS 1713 Introduction to Programming II Spring 2012 Daily Answers


Class 3:

  1.    Scanner scan = new Scanner(System.in);
       int value = scan.nextInt(6) + 1;
       System.out.println("The result is "+value);
    
  2.    public static int throwDice() {
          Random rand = new Random();
          return rand.nextInt(6) + rand.nextInt(6) + 2;
       }
    
  3. The sum of 5 and 7 is 57
  4. The value of 35 divided by 2 is 17
  5.    public static void printArray(int[] array) {
          if (array.length > 0)
             System.out.print(a[0]);
          for (int i=1;i<array.length;i++)
             System.out.print(a[i] + ", ");
       }