Lab2Exercise1.java - package week2demob import java.util.Scanner public class Lab2Exercise1 public static void main(String args Scanner kb = new

Lab2Exercise1.java - package week2demob import...

This preview shows page 1 - 3 out of 3 pages.

package week2demob; import java.util.Scanner; public class Lab2Exercise1 { public static void main(String[] args) { Scanner kb = new Scanner(System.in); while (true) { System.out.println("Enter a letter ('a','b','c','d','e' or 'q' to quit:"); char letter = kb.next().charAt(0); if (letter == 'a') { System.out.println("Student Name is: Lee Ming Shun"); System.out.println("Lecturer Name is: Mr Han Kee"); } else if (letter == 'b') { System.out.println("Enter a number for X;"); double x = kb.nextDouble(); System.out.println("Enter a number for Y;"); double y = kb.nextDouble(); System.out.println("Enter a number for Z:"); double z = kb.nextDouble(); double largest = largest(x, y, z); double smallest = smallest(x, y, z); System.out.println("Largest number is:" + largest); System.out.println("Smallest number is:" + smallest); } else if (letter == 'c') { System.out.println("Enter a number for M:"); int m = kb.nextInt(); System.out.println("Enter a number for N:"); int n = kb.nextInt(); int sum =0; if (m < n) { for (int i = 0 ; i <5; i++) { m = m +1; int j = m; int g =m; String str1 = Integer.toString(j); if (g % 2 ==1) sum+=g; System.out.print("Number sequence:" + str1 +""); System.out.println("The sum of all odd numbers between " + m + " and "+ n + " is " + sum);
Image of page 1
Image of page 2
Image of page 3

You've reached the end of your free preview.

Want to read all 3 pages?

  • One '14
  • Summation, Natural number, Prime number

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture