Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Main {
- static Scanner in = new Scanner(System.in);
- public static void main(String[] args) {
- tar1();
- tar2();
- tar3();
- tar4();
- tar5();
- tar6();
- tar7();
- tar8();
- }
- public static void tar9() {
- //is in the word document
- }
- public static void tar8() {
- int iBags,iSumBagsPlane = 0,iPrevBagsPlanes;
- int iPlaneMaxBags = 1,iPlaneMinBags = 1;
- boolean bTwoBags = true;
- //finds which plane had the maximum amount of carry on and the min amount
- //finds if there were planes with at least Passenger who had less than 2 bags
- for (int i = 1; i <= 20; i++) {
- iPrevBagsPlanes = iSumBagsPlane;
- iSumBagsPlane = 0;
- for (int j = 1; j <= 250; j++) {
- System.out.println("How many bags does passenger number " + j + " have as carry on");
- iBags = in.nextInt();
- iSumBagsPlane += iBags;
- if (iBags < 2)
- bTwoBags = false;
- }
- if (iSumBagsPlane > iPrevBagsPlanes)
- iPlaneMaxBags = i;
- if (iSumBagsPlane < iPrevBagsPlanes)
- iPlaneMinBags = i;
- }
- System.out.println("plane number " + iPlaneMaxBags + " had the maximum amount of bags");
- System.out.println("plane number " + iPlaneMinBags + " had the minimum amount of bags");
- if (bTwoBags)
- System.out.println("all the planes had more than two bags");
- else
- System.out.println("There were planes with passengers who had less than 2 bags");
- }
- public static void tar7() {
- int iMark,iSumClass = 0;
- double iAverageClass = 0,iAverageGrade = 0;
- //finds the average mark for a class and for the grade
- for (int i = 1; i <= 10; i++) {
- for (int j = 1; j <= 30; j++) {
- System.out.println("How much did student number " + j + " get in the test");
- iMark = in.nextInt();
- iSumClass += iMark;
- }
- iAverageClass = iSumClass/30.0;
- iAverageGrade += iAverageClass;
- System.out.println("The average mark for class number " + i + " is: " + iAverageClass);
- iSumClass = 0;
- }
- iAverageGrade = iAverageGrade/10.0;
- System.out.println("The average mark for the grade is: " + iAverageGrade);
- }
- public static void tar6() {
- int iNum,iNum1,iSum = 0;
- //receives an input the a list then finds difference between input and list
- for (int i = 1; i <= 5; i++) {
- System.out.println("Enter a number");
- iNum = in.nextInt();
- System.out.println("Enter another number");
- iNum1 = in.nextInt();
- iSum += iNum1;
- while (iNum1 != 0) {
- System.out.println("Enter another number");
- iNum1 = in.nextInt();
- iSum += iNum1;
- }
- System.out.println("The difference between the two numbers is: " + (iNum-iSum));
- iSum = 0;
- }
- }
- public static void tar5() {
- int iNum,iFactorial = 1;
- System.out.println("Enter a number");
- iNum = in.nextInt();
- //does factorial for an input by a user (ex:6! = 720)
- while (iNum >= 0)
- {
- for (int i = 1; i <= iNum; i++)
- iFactorial = iFactorial * i;
- System.out.println(iNum + "!" + " = " + iFactorial);
- iFactorial = 1;
- System.out.println("Enter a number");
- iNum = in.nextInt();
- }
- }
- public static void tar4() {
- int iMoney,iSumClass = 0,iSumSchool = 0,iStudents;
- //finds how many students are in a class and how much each student donated
- //finds average for class and for school and prints to screen
- for (int i = 1; i <= 30; i++)
- {
- System.out.println("How many students are in class number " + i + "?");
- iStudents = in.nextInt();
- for (int j = 1; j <= iStudents; j++)
- {
- System.out.println("How much did student number " + j + " donate?");
- iMoney = in.nextInt();
- iSumClass += iMoney;
- iSumSchool += iMoney;
- }
- System.out.println("Class number " + i + " donated a total of " + iSumClass + " shekels!");
- iSumClass = 0;
- }
- System.out.println("The school donated " + iSumSchool + " shekels");
- }
- public static void tar3() {
- int iNum,iNum2;
- //receives two pares of numbers and show the numbers from smallest to highest between the two
- for (int i = 1; i <= 20; i++)
- {
- System.out.println("Enter a number");
- iNum = in.nextInt();
- System.out.println("Enter a second number");
- iNum2 = in.nextInt();
- if(iNum2 < iNum)
- {
- for (int j = iNum2; j <= iNum ; j++)
- System.out.println(j);
- }
- else if(iNum2 > iNum)
- {
- for (int j = iNum; j <= iNum2 ; j++)
- System.out.println(j);
- }
- else
- System.out.println("The numbers your entered were equal");
- }
- }
- public static void tar2() {
- int iGrade,iSum = 0;
- //loops through 35 kids and finds average of all grades
- for (int i = 1; i <= 35; i++)
- {
- for (int j = 1; j <= 12 ; j++)
- {
- System.out.println("Enter your grades");
- iGrade = in.nextInt();
- iSum += iGrade;
- }
- System.out.println("The average of student number " + i + " is: " + (iSum/12.0));
- }
- }
- public static void tar1() {
- int iNum;
- //loops through and printss out 1- the number you entered
- for (int i = 1; i <= 10; i++) {
- System.out.println("Enter a number");
- iNum = in.nextInt();
- for (int j = 1; j <= iNum; j++)
- System.out.println(j);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement