import java.util.*;
public class Factors {
public static void main (String [] args){
System.out.println("Enter a number to find the factors for: ");
Scanner keyboard = new Scanner(System.in);
int input = keyboard.nextInt();
ArrayList<Integer> Factors = new ArrayList<Integer>();
for(int i = 1; i <= input; i++){
if(input % i == 0){
if(Factors.contains(i)){
break;
}
Factors.add(i);
Factors.add(input / i);
System.out.println("Factors are: " + i + " and " + input / i);
}
}
}
}
The second if statement is simply so it doesn't repeat factors. But I want it to print "Enter a number to find the factors for: and then read a user input on the same line. If I use println, then it goes to the next line. If I use print, then it won't ask "Enter a number to find the factors for: until I give an input. How can I fix this and why does it happen?
question from:
https://stackoverflow.com/questions/65910860/system-out-println-issue 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…