[Solved] Write a program that prints the multiplication of two selected numbers from a line [closed]

You can run something like this: int numOfLines; //stores num of lines that will be inputted Scanner reader = new Scanner(System.in); //assuming you already imported before this numOfLines = reader.nextInt(); //captures 1st user inputted value int[] nums = new int[numOfLines]; //creates array object to captures all further values for (int i = 0;i<numOfLines-1;i++){ nums[i] = … Read more

[Solved] Can Java delimit input itself, without explicit delimiters?

Assuming you’re using scanner, yes, it could. The scanner operates on the notion that a regexp serves as delimiter: Each match of the regex delimits, and whatever the regexp matches is tossed out (because nobody ‘cares’ about reading the spaces or the commas or whatever). The scanner then gives you stuff in between the delimiters. … Read more

[Solved] Why does entering “Δ to a Scanner result in the wrong character?

The value 65533 is 0xFFFD. This is the Unicode “Replacement Character” which is used in place of a character that is unrepresentable. It is normally displayed as “�”. The reason you are getting this could be because your standard input (keyboard?) is not capable of producing the character “Δ. Try putting this character into a … Read more

[Solved] Java Incompatible types: inputstream cannot be converted to scanner

private ArrayList<Student> readFile() throws FileNotFoundException { String fName = “p02-students.txt”; Scanner scan = new Scanner(new File(fName)); ArrayList<Student> studentList = new ArrayList<Student>(); while (scan.hasNext()) { String studentType = scan.next(); if (studentType.equals(“C”)) { studentList.add(readOnCampusStudent(scan)); } else { studentList.add(readOnlineStudent(scan)); } scan.nextLine(); } scan.close(); return studentList; } I didn’t get the error you mentioned earlier, but I was getting … Read more

[Solved] Java scanner reading garbage

You are reading a RTF Document. If you want to read the text only you can try reading it into a byte array and parsing out the text using swings rtfeditorkit. Path path = Paths.get(“path/to/file”); byte[] data = Files.readAllBytes(path); RTFEditorKit rtfParser = new RTFEditorKit(); Document document = rtfParser.createDefaultDocument(); rtfParser.read(new ByteArrayInputStream(data), document, 0); String text = … Read more

[Solved] I have an issue using tokens, scanning multiple inputs and executing them at the same time

If I understand correctly your Scanner is breaking on spaces. You want it to break on new lines: Scanner scanner = new Scanner(System.in); scanner.useDelimiter(System.getProperty(“line.separator”)); // this scans for lines while (scanner.hasNext()) { String input = scanner.next(); System.out.println(input); // take a look for yourself } 4 solved I have an issue using tokens, scanning multiple inputs … Read more

[Solved] Java StringBuffer cannot print out apostrophe

Tom, The problem is that one string is longer than the other one. import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); String elso = sc.nextLine(); String masodik = sc.nextLine(); String longestString = elso; String shortestString = masodik; if (shortestString.length() > longestString.length()){ shortestString = elso; longestString = … Read more

[Solved] Accept arbitrary multi-line input of String type and store it in a variable

From what I gather, you’re trying to get input from a user until that user types -1. If thats the case, please see my function below. public static void main (String[] args) { // Scanner is used for I/O Scanner input = new Scanner(System.in); // Prompt user to enter text System.out.println(“Enter something “); // Get … Read more