1. Engineering
  2. Computer Science
  3. lab 2 cse 110 principles of java programming topics ...

Question: lab 2 cse 110 principles of java programming topics ...

Question details

Lab 2 CSE 110: Principles of JAVA Programming Topics: ● Familiarization with basic data types. ● Using the Scanner Class. ● Learning how to use print command. ● Working on "String" type. Lab 2 - Basic data types: 1. Please copy the following code into your IDE and ensure it compiles. public class Lab2 { public static void main(String[] args) { Scanner scan=new Scanner(System.in); } } Step 1: Declare variables In this step, you need to define 6 variables. One integer, two doubles and three strings. Initialize all variables: Example: int age=0; // an integer called age // 2 double called num1, num2 // a String called firstName // a String called lastName // a string for fullName Step 2: Ask user to enter the variables: In this step, ask the user to enter variables. First of all, you need to define a Scanner to read input. After that you can read first name, last name, 2 numbers and age from the user using Scanner: // define a Scanner variable // example: Scanner scanner = new Scanner(System.in) // print enter the first name // read the first name using scanner You only need to define one scanner and you can read all inputs using this scanner. Don’t define multiple scanners. Step 3: Making full name: Now we have both first and last name, we need to form the full name from them. Remember that string concatenation can be done using '+' sign between variables: // Print full name + ” is “ + age + ” years old” Convert the full name to uppercase and print it: //Print “uppercase full name is: ” + fullname Step 4: Compare 2 numbers: Compare two double numbers that user entered. If number 1 is bigger print (number1 is bigger than number2), if number 2 is bigger than number 1 print(number 2 is bigger than number1) otherwise print number 1 is equal to number2. if command works like this if (x){ //condition1 } else if(y){ //condition2 } else{ //condition3 } // if num1 > num2: // print num1 is bigger than num2 //else if num1 < num2 // print num2 is bigger than num1 //else // print two numbers are equal

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution