WHAT'S NEW?
Loading...

Java code that prints highest and the sum of numbers

The user will input the list of numbers and print the highest in java

int counter = 1;
        int number;
        int limit=0;
        int largest = 0;

        Scanner input = new Scanner(System.in);

        System.out.println("Enter limit number");
        limit = input.nextInt();

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

        while(counter < limit)
        {
            System.out.println("Enter the number: ");
            number = input.nextInt();

            if(largest < number) {
                largest = number;
            }
            counter++;
        }
        System.out.println("The largest number is " + largest);
    }

The user will input the list of number and print the total sum.

 int sum=0,val,n,i;
        Scanner sc=new Scanner(System.in);
        System.out.print("Enter number of data points:");
        n=sc.nextInt();
        for(i=0;i<n;i++){
           System.out.print("Values "+i+":");
           val=sc.nextInt();
           sum+=val;
          }
        System.out.println("Total:"+sum);
    }
    static void message(String myText){
        System.out.println(myText);
    } 

0 comments:

Post a Comment