Scanner(System.in); x = scan.nextInt(); y = scan.nextInt(); if(y >= x){ for(int i=x; i<=y; i = i + 5) { System.out.print(i+ " "); (The problem line) } } else{ System.out.print("Second integer can't be less than the first."); } }
Java - Help Please
How do I output this statement as a horizontal statement with a newline? Everytime I use System.out.println, it makes the entire output vertical instead of horizontal. Program below.
import java.util.Scanner;
public class LabProgram {
public static void main(String[] args) {
int x;
int y;
Scanner scan = new Scanner(System.in);
x = scan.nextInt();
y = scan.nextInt();
if(y >= x){
for(int i=x; i<=y; i = i + 5)
{
System.out.print(i+ " "); (The problem line)
}
}
else{
System.out.print("Second integer can't be less than the first.");
}
}
}
Step by step
Solved in 2 steps with 2 images
Whenever is use System.out.print, it prints horizontally but it doesn't have a newline, thus, it comes back incorrect on the website I'm using. How do I make it horizontal with a newline?