Question: 1. Practice the following scenarios in a Java program: a. Declare a variable x of type int, and assign the value 130 to it. Now

 1. Practice the following scenarios in a Java program: a. Declare

1. Practice the following scenarios in a Java program: a. Declare a variable x of type int, and assign the value 130 to it. Now declare another variable y of type byte and try to assign the value of x to it (i.e. y=x; ). See what happens? Is this upcasting or down casting? b. Try to lower the value of x to less than 127 . Does it work? Why? c. Change the value of x back to 130 . Try to use explicit down casting to assign the value of x to y (i.e. y=( byte) x; ) d. Print the value of y, is it 130 ? If not, then why not? Why the value is what it is? 2. Write a program that prints a multiplication table of 5. You must use a while loop to print the multiplication table. You must not use the break statement anywhere in your code. 3. Copy and modify the above program so that it uses a for loop and the break statement in the loop 4. Write a program that prints only odd numbers from 1 to 99 . You can either use a while loop or a for loop, but you must make use of the cont inue statement in your loop. 5. Write a simple program that accepts an integer input from the user and prints it back as follows: Enter a number: 9 You entered: 9 Enter a number: the program must use a do-while loop and keep repeating until the user types 1. The program will exit as soon as the user enters 1. 6. Write a custom method in your Java program that takes input as an integer and returns true if the input number is a prime number otherwise it returns false. The signature of the method must match the following: public static boolean isprime (int number) \{\} Note: a prime number is a number whose only factors are the number itself and 1. You must not use any Java built-in math libraries to determine the primality of the input number

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!