Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Computer Programming Lab 9 Exercise 1 Source Code package excercise1; import java.util.Scanner; public class Excercise1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); int sumOfPositive=0; int sumOfNegative=0,sum=0; double count=0; System.out.print( "Enter an integer, the input ends with 0:"); int number=input.nextInt(); if (number==0) System.out.println( "No numbers entered except 0 " ); else{ while(number!=0) { count++; sum+=number; if(number>0) sumOfPositive++; else sumOfNegative++; number=input.nextInt(); } System.out.println( "The number of positives is " + sumOfPositive); System.out.println( "The number of negatives is " + sumOfNegative); System.out.println( "The total is " +sum); System.out.println( "The average is " +sum/count); } } } Exercise 2 Source Code package javaapplication4; import java.util.Scanner; public class JavaApplication4 { public static void main(String[ ] args) { Scanner input = new Scanner(System.in); System.out.print( "Enter positive integer greater than or equal 2: " ); int number= input.nextInt(); System.out.println( "The factors of “ +number+ " are :" ); int factor=2; do{ if(number%factor==0) { System.out.printf( "%d, " ,factor); number/=factor; } else factor++; }while(factor<=number); }} Exercise 3 Source Code : package exercise3; import java.util.Scanner; public class Exercise3 { public static void main(String[] args) { Scanner input=new Scanner (System.in); System.out.print( "Enter the number of students: " ); int numOfStudent= input.nextInt(); System.out.print( "Enter student first name only: " ); String student1= input.next(); System.out.print( "Enter a student score: " ); double score1= input.nextDouble(); for(int i=0 ; i<numOfStudent-1 ; i++) { System.out.print( "Enter student first name only: " ); String student= input.next(); System.out.print( "Enter a student score: " ); double score= input.nextDouble(); if(score>score1) { student1=student; score1=score; } } } System.out.println( "Top student " +student1+" 's score is " +score1); }