0

How would I print out a user input given the certain amount of inputs needed?

import java.util.Scanner;
public class SilentAuction {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int amount = sc.nextInt();
        for (int i = 1; i <= amount; i++) {
            System.out.println();//need to write "int sm = sc.nextInt;" and "String s = sc.nextLine;"
        }
    }
}
John Conde
  • 217,595
  • 99
  • 455
  • 496
Jennifer
  • 13
  • 5
  • `System.out.println(sc.nextInt());`? – Unmitigated Aug 09 '21 at 21:27
  • 4
    pro tip: use summarized titles instead of very long titles, and put the rest of the information in the body – I_love_vegetables Aug 10 '21 at 02:58
  • When you say, amounts of input. Do you mean the amount entered by the user or the number of characters/digits entered? I see the class name is SilentAuction. So, are you trying to compare previously entered amount with the current amount? Or are you trying to find the highest amount bid? – digvijaykatoch Aug 10 '21 at 16:20

1 Answers1

0

You're going to hit a common issue if you mix nextInt() and nextLine() methods. You'd be better off using nextLine() and trying to parse the content.

public class SilentAuction {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int amount = Integer.parseInt(sc.nextLine());
        for (int i = 0; i < amount; i++) {
            String s = sc.nextLine();
            int sm = Integer.parseInt(sc.nextLine());
            System.out.println(s + " : " + sm);
        }
    }
}
Tim Hunter
  • 826
  • 5
  • 10