i know small about java..but this is beyond my limitation.I create a code that infinite input and find the largest and
smallest number by using top-down approach..to stop the loop i use number 0.
Still i don't get the right out put cause what is the last input its also the output..
I would appreciate some assistance in the form of making me aware of some sort of hints as to what I could do to accomplish this task.
Here is the code that I have so far:
class largestandsmallestTopdown{
public static void main(String[]args){
int input;
int max;
int min;
print("Enter Integer: ");
input=IntegerInput();
max=LargeInt(input);
min=SmallestInt(input);
println("The largest: "+max
+"\nThe Smallest: "+min);
}
static void print(String str){
System.out.print(str);
}
static int IntegerInput(){
Scanner sc = new Scanner(System.in);
int input;
input = sc.nextInt();
while(input>0){
System.out.print("Enter Integer: ");
input = sc.nextInt();
}
return input;
}
static int LargeInt(int input){//The problem is here..the out put should be
int max=0; //the largest number
if(input>max){
max=input;
}
return max;
}
static int SmallestInt(int input){//And here the out put should be
int min=9999; //the smallest number
if(input<min){
min=input;
}
return min;
}
static void println(String str){
System.out.println(str);
}
}
Thanks to all of you in advance!

New Topic/Question
Reply



MultiQuote





|