Skip to content

CSE21P8 - Object Oriented Programming - I Lab

Basic Java Logic and Number/String Problems

Term 161

Exp 8. A palindrome is a sequence of characters that reads the same backward as forward. For example, each of the following five-digit integers is a palindrome: 12321, 55555, 45554 and 11611. Write an application that reads in a five digit integer and determines whether it's a palindrome. If the number is not five digits long, display an error message and allow the user to enter a new value.

Exp 9. A positive integer is prime, if it's divisible by only 1 and itself. For example, 2, 3, 5 and 7 are prime, but 4, 6, 8 and 9 are not. The number 1, by definition, is not prime.

  1. Write a method that determines whether a number is prime.
  2. Use this method in an application that determines and displays all the prime numbers less than 10,000. How many numbers up to 10,000 do you have to test to ensure that you've found all the primes?

Term 171

Exp 8. A positive integer is prime, if it's divisible by only 1 and itself. For example, 2, 3, 5 and 7 are prime, but 4, 6, 8 and 9 are not. The number 1, by definition, is not prime.

  1. Write a method that determines whether a number is prime.
  2. Use this method in an application that determines and displays all the prime numbers less than 10,000. How many numbers up to 10,000 do you have to test to ensure that you've found all the primes?

Exp 9. Write a program in java that reads one line of text as input in lower case letter and convert each letter into upper case.

Term 191

Exp 4. A palindrome is a sequence of characters that reads the same backward as forward. For example, each of the following five-digit integers is a palindrome: 12321, 55555, 45554 and 11611. Write an application that reads in a five digit integer and determines whether it's a palindrome. If the number is not five digits long, display an error message and allow the user to enter a new value.

Exp 5. Write a Java program to remove the duplicate elements of a given array and return the new length of the array.

Exp 6. A positive integer is prime, if it's divisible by only 1 and itself. For example, 2, 3, 5 and 7 are prime, but 4, 6, 8 and 9 are not. The number 1, by definition, is not prime.

  1. Write a method that determines whether a number is prime.
  2. Use this method in an application that determines and displays all the prime numbers less than 10,000. How many numbers up to 10,000 do you have to test to ensure that you've found all the primes?

Exp 12.

  1. Write a program in Java to print all prime numbers between 1 to 100.
  2. Write a program to determine the sum of the following series for a given value of \(n\).
\[ 1 + 2^2 + 3^2 + 4^2 + \cdots + 10^2 + \cdots + N^2 \]

Term 211

Exp 05. Some websites impose certain rules for passwords. Write a method in Java that checks whether a string is a valid password. Suppose the password rules are as follows:

  • A password must have at least eight characters.
  • A password consists of only letters and digits.
  • A password must contain at least two digits.

Write a Java program that prompts the user to enter a password and displays Valid Password if the rules are followed or Invalid Password otherwise.