Following is the piece of code i have used in c/c++ which is fairly simple:
while ((scanf_s("%d", &num) == 1)&&num>0)
Below is the usual java code to read input:
try(Scanner n1 = new Scanner(System.in))
{
System.out.println("Enter the number of days");
while(n1.hasNextInt())
{
days = n1.nextInt();
//some stmts
n1.nextLine();
}
}
How can use this while to read the input as well as compare the value in a single "while" like i can do in c and c++;
Aucun commentaire:
Enregistrer un commentaire