codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  gods  codename at 06:57 on Tuesday, September 06, 2005
 

i am having problem to do looping on the integer number.The program ask the user to enter an integer numbers with a sentinel..and will stop only if user key in 9999 value, if number equal to 9999 the program will do the task listed below:
1.total number of integer being input
2.summation of the integer number
3.average of the intger number
4.max&min number

how do i process the task after integer is being input???my program doesnt do the task after pressign the 9999....my code as follow
for(i=0;i<100;i++){
System.out.print("Enter integer number:")
number=input.readInt();
if (number==9999){
do {

sum=sum+i*i;
average=sum/n;

  Re: problem with integer numbers  kanad at 08:35 on Tuesday, September 06, 2005
 

Hello codename study this
----
import java.io.*;
class intOnly
{
BufferedReader buffer;
String entered="";
int userNo=0,counter=0,sum=0,max=0,min=0;
public static void main(String[] args)
{
new intOnly();
}
intOnly()
{
try
{
buffer=new BufferedReader(new InputStreamReader(System.in));
while(userNo!=9999)
{
System.out.print("Enter Integer ");
entered=buffer.readLine();
if(isNumeric(entered) && !entered.trim().equals("9999"))
{
counter++;//Counter
if(counter==1) //first no considered min and max
{
min=Integer.parseInt(entered);
max=Integer.parseInt(entered);
userNo=Integer.parseInt(entered);
}//if
else
{
userNo=Integer.parseInt(entered);
if(userNo<min)
{
min=userNo;
}//min
if(userNo>max)
{
max=userNo;
}//max

}//else counter==1

}//if isNumeric
else
{
break;
}
sum=sum+userNo;
System.out.println();
}//while

System.out.println("User Entered "+counter+" Nos.");
System.out.println("Min "+min);
System.out.println("Max "+max);
System.out.println("Sum "+sum);
if(counter!=0)
System.out.println("Avg "+(sum/counter));

}//try
catch (Exception E)
{
System.out.println(E);
}
}

public boolean isNumeric(String entered)
{
boolean No=true;

for (int i=0;i<entered.length();i++ )
{

if(entered.charAt(i)>46 && entered.charAt(i)<58)
{
No=true;
}
else
{
No=false;
System.out.println("Please Enter Integer only");
break;
}

}//for

return No;

}//isNumeric

}


  god  codename at 11:56 on Tuesday, September 06, 2005
 

thanx kanad,this helps me a lot, wht if i want to add additional 2 task of type boolean like this one:

a.Prints a Boolean (true or false) if some of them are less than 20
b.Prints a Boolean (true or false) if all of them are between 10 and 90

the output is like this one:
At least one number was < 20:<true or false>
All numbers were (10 <= n >= 90) : <true or false>]

i am having problem with it, can u help me on this




import java.io.*;
class intOnly
{
BufferedReader buffer;
String entered="";
int userNo=0,counter=0,sum=0,max=0,min=0;
public static void main(String[] args)
{
new intOnly();
}
intOnly()
{
try
{
buffer=new BufferedReader(new InputStreamReader(System.in));
while(userNo!=9999)
{
System.out.print(("Enter the number with <return>(9999 to stop): "));
entered=buffer.readLine();
if(isNumeric(entered) && !entered.trim().equals("9999"))
{
counter++;//Counter
if(counter==1) //first no considered min and max
{
min=Integer.parseInt(entered);
max=Integer.parseInt(entered);
userNo=Integer.parseInt(entered);
}//if
else
{
userNo=Integer.parseInt(entered);
if(userNo<min)
{
min=userNo;
}//min
if(userNo>max)
{
max=userNo;
}//max

}//else counter==1

}//if isNumeric
else
{
break;
}
sum=sum+userNo;
System.out.println();

if(userNo<20)
{
boolean userNo=true;
boolean userNo=false;
}
else
{
break;
}
if(userNo>=10 && userNo<=90)
{
boolean userNo=true;
boolean userNo=false;
}
System.out.println("The number of the integers is : "+counter+" Nos.");
System.out.println("\nThe sum of the integers is :"+sum);
if(counter!=0)
System.out.println("The average of the integers is :"+(sum/counter));
System.out.println("\nThe Min of the integers is :"+min);
System.out.println("\nThe max of the integers is :"+max);
System.out.println("At least one number was < 20:"+userNo);
System.out.println("All numbers were (10 <= n >= 90):"+userNo);



}//try
catch (Exception E)
{
System.out.println(E);
}
}

public boolean isNumeric(String entered)
{
boolean No=true;

for (int i=0;i<entered.length();i++ )
{

if(entered.charAt(i)>46 && entered.charAt(i)<58)
{
No=true;
}
else
{
No=false;
System.out.println("Please Enter Integer only");
break;
}

}//for

return No;

}//isNumeric

}



  Re: problem with integer numbers  codename at 01:08 on Wednesday, September 07, 2005
 

problem solved.TQ








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Why Use Method?
•  Re: Help with filesystem object & displaying in a table
•  Re: Genetic Algorithm Help
•  Re: How to make an investment calculator
•  Re: line breaks in GUI
•  Re: Graph in Gui...
•  Graph in Gui...
•  Re: Counting zero values in a string
•  Re: Help!


Recent Articles
Multiple submit buttons with form validation
Understanding Hibernate ORM for Java/J2EE
HTTP screen-scraping and caching
a javascript calculator
A simple way to JTable
Java Native Interface (JNI)
Parsing Dynamic Layouts
MagicGrid
Caching With ASP.Net
Creating CSS Buttons


Site Survey
Help us serve you better. Take a five minute survey. Click here!

© Copyright codetoad.com 2001-2005