What's new

Java Pa help naman po dito sa JAVA ko.

Hamburger24

Elite
Joined
Jul 1, 2017
Posts
1,153
Reaction
3,333
So eto po problem ko yung lowest number naka default lagi sa "0" . pa help naman po

1645897032646.png

Java:
import java.util.Scanner;

    public class main{
        public static void main(String[] args){
            Scanner input = new Scanner(System.in);
            int number;
            int max = 0;
            int min = 0;
            
                  for (int x = 0; x<5; x++){
                        System.out.print("Enter a number 1: ");
                        number = input.nextInt();
                        System.out.print("Enter a number 2: ");
                        number = input.nextInt();
                        System.out.print("Enter a number 3: ");
                        number = input.nextInt();
                        System.out.print("Enter a number 4: ");
                        number = input.nextInt();
                        System.out.print("Enter a number 5: ");
                        number = input.nextInt();
                
                        
                        if (x == 0 || number > max){
                            max = number; 
                            break;
                        }               
                        if (x == 0 || number < min){
                            min = number; 
                        
                        }               
                  }                 
                  System.out.println("\n Highest number is " + max);
                  System.out.println("\n Lowest number is " + min);
            }
     }
 

Attachments

bat may for loop ka? ano ba expected output?

Java:
import java.util.Scanner;

    public class main{
        public static void main(String[] args){
            Scanner input = new Scanner(System.in);
            int number;
            int max = 0;
            int min = 0;
            
                for (int x = 0; x<5; x++){
                    System.out.print("Enter a number "+(x+1)+": ");
                    number = input.nextInt();
                    if(x==0){
                        min = number;
                        max = number;
                    }
                    if(number>max){
                        max = number;
                    }
                    if(number<min){
                        min = number;
                    }
                }
                  System.out.println("\n Highest number is " + max);
                  System.out.println("\n Lowest number is " + min);
            }
     }
 
Last edited:
Top