You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Creating multiple scanners on System.in upsets the predictability of program behavior, especially when System.in has been re-directed.

Noncompliant Code Example

import java.util.Scanner;

public class InputLibrary{

   public static int getInt()

Unknown macro: {       System.out.println("Please enter an int}

   public static int getDouble()

Unknown macro: {       System.out.println("Please enter a double}

}

Compliant Code Example

import java.util.Scanner;

public class InputLibrary{

   private static Scanner in = new Scanner(System.in);

   public static int getInt()

Unknown macro: {       System.out.println("Please enter an int}

   public static int getDouble()

Unknown macro: {       System.out.println("Please enter a double}

}

  • No labels