Program of make a function that take number from user wants and at end count the negative, positive, zero numbers in java.
import java.util.*;
public class function {
public static void main(String[] args) {
int pos=0,neg=0,zero=0,inpute=0;
Scanner sc=new Scanner(System.in);
do{
System.out.print("enter a number=");
int num=sc.nextInt();
if(num>0)
pos++;
else if(num<0)
neg++;
else
zero++;
System.out.println("press 1 for continue and 0 for stop=");
inpute=sc.nextInt();
}while(inpute==1);
System.out.println("positive="+pos);
System.out.println("negative="+neg);
System.out.println("zero="+zero);
}
}
■》Output->
Enter a number=23
press 1 for continue and 0 for stop=1
enter a number= -8
press 1 for continue and 0 for stop=1
enter a number=0
press 1 for continue and 0 for stop=1
enter a number=67
press 1 for continue and 0 for stop=0
positive=2
negative=1
zero=1
Comments
Post a Comment