http://javacodespot.blogspot.com/2011/04/java-programming-using-scanner-for-user.html
import java.util.*;
public class ScannerClass
{
public static void main(String[] args)
{
Scanner scan=new Scanner(System.in);
System.out.print("1st num: ");
int num1=scan.nextInt();
System.out.println();
System.out.print("2nd num: ");
int num2=scan.nextInt();
int sum=num1+num2;
System.out.println();
System.out.println("Sum: "+sum);
}
}
Java has no built-in framework for dealing with biometric data, fingerprints included. If you wanted to build your own class, it would be sensible to store the information in the same way your fingerprint scanner passed it on. If the scanner gives you an image, store the image. If the scanner gives you a bunch of numbers, store a bunch of numbers.
import java.util.*; public class Example { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.println("Please enter a Double:"); double numDouble = in.nextDouble(); } }
To arrange numbers in ascending order using Java, you can utilize the Scanner class to read input from the user and then sort the numbers using an array. Here's a simple example: import java.util.Arrays; import java.util.Scanner; public class AscendingOrder { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Enter the number of elements: "); int n = scanner.nextInt(); int[] numbers = new int[n]; System.out.println("Enter the numbers:"); for (int i = 0; i < n; i++) { numbers[i] = scanner.nextInt(); } Arrays.sort(numbers); System.out.println("Numbers in ascending order: " + Arrays.toString(numbers)); scanner.close(); } } This program collects a specified number of integers from the user, sorts them using Arrays.sort(), and then displays the sorted list.
by making that class final
You can use the full name of the class. In your case example: java.util.Scanner scanner = new java.util.Scanner(System.in);
import java.util.Scanner;public class Ooops{public static void main (String[]args){Scanner kb= new Scanner (System.in);int ave;int ctr=1;while(true){System.out.println("Enter the number");int no = kb.nextInt();ave+=no/ctr;ctr++;}}}
We can create a exception sub class by extending Exception class available in java
class is a blueprint which does not have its own existence but it can pass all of its feature to its child classes.
import java.util.*; class even{ public static void main(String[]args){ Scanner cons = new Scanner(System.in); int even; even = cons.nextInt(); if(even % 2 == 0) { System.out.println(even); } } }
import java.util.*; public class avg { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.print("How many numbers: "); int amount = input.nextInt(); double [] numbers = new double[amount]; double count = 0; double avg; for(int i = 0; i < numbers.length; i++){ System.out.print("Number: "); numbers[i] = input.nextDouble(); count += numbers[i]; } avg = count / amount; System.out.println(avg); } }
You create a text file with a .java extension. Then you put a proper class definition.
You need to use File class to create file in java and than Reader class implementation such as BufferedReder to read content.