This exam has 2 parts a written part and a programming part.
For the written part type your answers into a text file. For the programming part you must write a complete java program.
Upload the written part using the link final
Upload the program using the fprogram1
at COL
Note: When submitting the program you must submit the .java file NOT the .class file.
This is an exam. You can use your book but you must do your own work. No help from tutors or anyone.
a) number1 b) level c) 4sale d) my String
a) int x = 6.5; b) if ( x = 100) ++x; c) if ( x < 30 ) ++x; System.out.println( x + “ is less than 30 “ ); else System.out.println( x + “ is bigger than or equal to 30 “ );
a) z = c/b – b/a; b)z = c % b - a
int a = 10, b = 20; a) if ( a > 30 || a < 15) System.out.println(“executed if “); else System.out.println(“executed else “); b) if ( b > 30 ) { if ( a > 20 ) System.out.println(“Second if “); else System.out.println( “First else“); } else System.out.println(“Second else “); c) if( b >= 0 && a < 10) System.out.println(“executed if”); else System.out.println(“execute else”);
a) for( int i = 0; i <= 6; i += 3) System.out.println("i is " + i); b) int x = 20; if( x % 2 == 0 ) System.println("X is odd"); else System.out.println("X is even");
for(int i = 1; i <= 20; i++) System.out.println(i + " squared is " + i * i);
final double rate = 6.25; char pass = 'P';
True or false, the following statements are correct. If false, you must Explain!
a) rate = 9.35; b) pass = "pass";
int [] X = {22,44,88}; int [] Y = {11,33,55}; Y = X; System.out.println( Y[0] ); System.out.println( X[ X.length – 1] );
public int lastIndexOf (char ch) that returns the index, within the string through which the method was called, of the last occurrence of the specified character. If the parameter character does not appear in the string, the method returns -1. YOUR TASKS: You must complete the code that follows, so that it will do the following: 1. Read a String from the user, using the Scanner class, and store it in a variable called s1 2. Using a call to the method lastIndexOf of the String class described above, find the index in s1 of the last occurrence of the character ‘a’ and store the result in a variable called lastIndex 3. Display with a JOptionPane or print to terminal the results of Step 2 above. import javax.swing.JOptionPane; import java.util.Scanner; public class Problem1 { public static void main (String[] args) { Scanner console = new Scanner (System.in); } }
1.Takes an array of integers as a parameter 2. Checks for the presence in the array of at least one pair of adjacent increasing integers, i.e. two integers right next to each other in the array that differ by one, with the smaller one appearing first from left to right (2,3 or 45,46,....) 3. Returns a boolean variable that has been set to true if the array contains at least one such pair, or that has been set to false if it does not contain any such pairs. YOUR TASKS: 1. Complete the code of the proposed method found below, according to the specifications given above. 2.Propose a suite of three arrays of integers of length 5 that would be good candidates to test the correctness of your method 3.For each of the arrays you proposed in Step 2 give a clear explanation for why you think the chosen array is a significant test case private boolean hasWantedPair(int[] nums) { boolean hasPair = false; return hasPair; }
calories = bodyWeight * 19;
Name your class Calories
You must use a method (function) to do the computation. In order to recieve credit you have to use a function to do the computation. No function , no creditYou must run the program in a loop allowing the user to terminate the program.