Consider the statements int x y char ch Scanner console new
Consider the statements:
int x, y;
char ch;
Scanner console = new Scanner(System.in);
and the input: 46 A 49
Write 3 or 4 Java statements that use the console object to read the input values in the order specified that store 46 in x, A in ch and 49 in y. You do not have to provide statements to prompt the user for the input values. Assume console has already been declared as a Scanner object.
Solution
import java.util.*;
import java.util.Scanner;
public class store {
public static void main(String[] args) {
int x,y;
char ch;
// Scanner console = new Scanner(System.in);
String str=\"46 A 49\";
str = str.replaceAll(\"[-+.^:,]\",\"\"); // removes all charecters that we included [] and replaceAll with \"\"
//System.out.println(str+str.length());
String[] result = str.split(\"\\\\s+\"); // splits string by space and result will store in array
System.out.println(result[0]+\"in x, \"+result[1]+\" in ch and \"+result[2]+\"in y\");// here displaying
}
}
