import java.util.Scanner;
import java.util.Random; public class Part1_Student {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
Random rand = new Random();
final int MINIMUM = 1001;
int rint;
int nstudents;
String name;
System.out.print("Enter the number of students: ");
nstudents = scan.nextInt();
if (nstudents >= 1) {
for (int i = 0; i == nstudents; i++) {
System.out.println("Enter the student full name (separated by .): ");
name = scan.next();
rint = rand.nextInt(Integer.MAX_VALUE - MINIMUM) + MINIMUM;
System.out.println(name + "###" + rint );
}
}
else {
System.out.print("Error number should be greater than 0");
}
}
}
After I ran the code and insert the number of students the program ends as if my for loop isn't running (i have no errors in my code so I am not sure what's wrong). and I tried inserting 0 to check if my if loop is the program but no the code runs normally and prints "Error number should be greater than 0".
Can someone check the code to see what I should fix. the whole purpose of the code is to: Write a program that prompts the user to enter the number of students and then asks for each student full name. After it, a password composed of the first character of the student’s name and a random positive integer (>1000) is generated.
Aucun commentaire:
Enregistrer un commentaire