public void readShapeData() throws IOException { Scanner in = new Scanner(System.in); try { System.out.println("Enter the width of the Rectangle: "); width = in.nextDouble(); System.out.println("Enter the height of the Rectangle: "); height = in.nextDouble(); } finally { in.close(); } }
Scanner sc = new Scanner(System.in); while (!sc.hasNext("exit")) { System.out.println( sc.hasNextInt() ? "(int) " + sc.nextInt() : sc.hasNextLong() ? "(long) " + sc.nextLong() : sc.hasNextDouble() ? "(double) " + sc.nextDouble() : sc.hasNextBoolean() ? "(boolean) " + sc.nextBoolean() : "(String) " + sc.next() ); }
Scanner scanner = new Scanner("Test string: 12.3 dog 12345 cat 1.2E-3"); while (scanner.hasNext()) { if (scanner.hasNextDouble()) { Double doubleValue = scanner.nextDouble(); } else { String stringValue = scanner.next(); } }
public static void main(String[] args) { Sales s1 = new Sales(); Scanner input = new Scanner(System.in); System.out.print("Enter total Sales"); s1.setTotalSales(input.nextDouble()); System.out.print("Enter number of Items: "); s1.setNumOfItems(input.nextInt()); System.out.printf("$%.2f", s1.getCommission()); input.close(); }
int i, j; try { s = new Scanner(new BufferedReader(new InputStreamReader(mixFiltersStream, "UTF-8"))); s.useLocale(Locale.US); line = s.nextLine(); taps.add(s.nextDouble()); } finally { if (s != null) {
Scanner scanner = new Scanner(content.toString()); scanner.useLocale(locale); switch (nonNillOutput.getType()) { return scanner.nextInt(); } else { throw new AvroConversionException("Cannot convert " return scanner.nextDouble(); } else { throw new AvroConversionException("Cannot convert "
Scanner scanner = new Scanner(new File("pathToYourFile")); List<Double> doubles = new ArrayList<Double>(); while(scanner.hasNextDouble()){ doubles.add(scanner.nextDouble()); } Collections.sort(doubles);
public static void main(String[] args) { Scanner input = new Scanner(System.in); int counter = input.nextInt(); Exam[] arr = new Exam[counter]; for (int i = 0 ; i < counter ; i++) { double mark = input.nextDouble(); double weight = input.nextDouble(); arr[i] = new Exam(mark, weight); } System.out.println("The average mark for your "+counter+" assignments/exams is "+ Exam.getAverage(arr)); }
public static void main(String[] args) { double a, b, c; Scanner s = new Scanner(System.in); //1.User inputs the sides of a triangle System.out.println("Please enter the sides of the triangle:"); a = s.nextDouble(); b = s.nextDouble(); c = s.nextDouble(); if(a==b && b == c) { System.out.println("The triangle is a equalateral triangle"); } }
int i, j; try { s = new Scanner(new BufferedReader(new InputStreamReader(mixFiltersStream, "UTF-8"))); s.useLocale(Locale.US); line = s.nextLine(); taps.add(s.nextDouble()); } finally { if (s != null) {
Scanner scanner = new Scanner(System.in); System.out.print("CSV: "); double csv = scanner.nextDouble(); System.out.print("CR: "); double cr = scanner.nextDouble(); if (csv < 0.0) { while (cr > 0.0) { System.out.println("CR cannot be positive since CSV is negative."); System.out.print("CR: "); cr = scanner.nextDouble(); } }
public static void main (String[] args) { Scanner input = new Scanner(System.in); double[] numbers = new double[5]; for (int i = 0; i < numbers.length; i++) { System.out.println("Please enter number"); numbers[i] = input.nextDouble(); } }
public static void rangeCalculator(int startPoint, int endPoint){ Scanner input = new Scanner(System.in); System.out.print("Enter gradient:"); double gradient = input.nextDouble(); System.out.print("\nEnter intercept:"); double intercept = input.nextDouble(); for(int i=startPoint; i<=endPoint; i++){ System.out.println("y="+gradient+"x + " +intercept+"\t" + "input:"+i + " output:" + (gradient*i + intercept)); } }
Scanner s = new Scanner(System.in); System.out.println("Please enter the sides of the triangle:"); a = s.nextDouble(); b = s.nextDouble(); c = s.nextDouble(); System.out.println("The triangle is a equalateral triangle");
public static void main(String[] args) { double radius; double height; Scanner in = new Scanner(System.in); System.out.print("Enter radius: "); radius= in.nextDouble(); System.out.print("Enter height: "); height= in.nextDouble(); // call this System.out.println("area " + output(Calculations(radius,height))); }
Scanner scanner = new Scanner(System.in); System.out.println("Give width\n"); double width = scanner.nextDouble(); System.out.println("Give period"); int period = scanner.nextInt(); System.out.println("\nInsert width peak to peak:"); double p2p = scanner.nextDouble();
public static void main(String[] args) { Scanner scanL = new Scanner (System.in); System.out.print("Please enter the length of the rectangle: "); double L = scanL.nextDouble(); System.out.print("Please enter the length of the rectangle: "); double W = scanL.nextDouble(); Rectangle rectangle = new Rectangle(l,w); double rectangleArea = rectangle .FindArea(); System.out.println("The area of a unit rectangle is " + rectangleArea); double rectanglePermiter = rectangle.FindPerim(); System.out.println("The permimiter of the unit rectangle is " + rectanglePermiter); }
Scanner in = new Scanner(System.in); DoubleSummaryStatistics stats = IntStream.range(0, in.nextInt()) .mapToDouble(i -> in.nextDouble()) .summaryStatistics(); System.out.println(stats);
double ans = 0; Scanner input = new Scanner(System.in); int x = 9 //Or some other number for(int i = 1; i <= x; i++){ System.out.print("Enter Number #" + i); ans += input.nextDouble(); } System.out.println("The Average of the numbers you gave is:" + ans / x);