Hi every body

i have a Question

How to find lowest number?

this my code

is there any mistake ?

``````import java.util.Scanner;

public class MaxNumber {

public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int min = 0 ; int count=1;

System.out.println("Enter a number : ");
int num=input.nextInt();

for(;;){
if(num==0)
break;

if(num<=min){
num=min;
count=0;
}
if (num==min)
count++;

System.out.println("Enter a number : ");
num=input.nextInt();

}
System.out.println("The min number is : " + min );

System.out.println("The occurrence count of the min number is : " +  count);
}
}``````

``````if(num<=min){
num=min;
count=0;
}``````

You start with min=0, so how often will num be less that that?

``````for(;;){
if(num==0)
break;
...``````

I see what you intended here, but the more usual way to code that is

``````while(num != 0) {
...``````

This is your homework, so you must write the code.
You hve a problem with
if(num<=min){
min is 0, so num will never be less than min

## All 5 Replies

``````if(num<=min){
num=min;
count=0;
}``````

You start with min=0, so how often will num be less that that?

``````for(;;){
if(num==0)
break;
...``````

I see what you intended here, but the more usual way to code that is

``````while(num != 0) {
...``````

And finally, indenting your code will make it much easier to read and debug.

can you write it in code?

because i do not understand

This is your homework, so you must write the code.
You hve a problem with
if(num<=min){
min is 0, so num will never be less than min

thank you it's work now

``````import java.util.Scanner;

public class MaxNumber {

public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int min = 0 ; int count=1;
System.out.println("Enter a number : ");
int num=input.nextInt();
min=num;
for(;;)
{

if(num==0)
break;

if(num<=min)
{
min=num;
count=0;
}

System.out.println("Enter a number : ");
num=input.nextInt();

}

System.out.println("The min number is : " + min );

}
}``````

thank you it's work now

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.