Lab 2.1.1 Create a program that will perform the following tasks: create a progr
ID: 3860142 • Letter: L
Question
Lab 2.1.1
Create a program that will perform the following tasks:
create a program named Lab2_1_1
write an if statement that will print out your full name (first and last) IF the user types in the
number 1
Lab 2.1.2
Create a program that will perform the following tasks:
create a program named Lab2
write an if statement that will print out your full name (first and last) IF the user types in the number 1
write a statement that will print out "thanks!" no matter what number is entered
Submit the file
Lab 2.1.3
Create a program that will perform the following tasks:
create a program named Lab3
the program will ask the user to enter a number
create an if statement that will test to see if the number is a negative number (HINT any number < 0 is negative)
if the number is positive the program will print out "the number is positive". If the number is negative the program will print out "the number is negative".
Explanation / Answer
Lab2_1_1.java
import java.util.Scanner;
public class Lab2_1_1 {
public static void main(String[] args) {
String firstName = "Suresh";
String lastName = "Murapaka";
Scanner scan = new Scanner(System.in);
System.out.print("Enter the number: ");
int n = scan.nextInt();
if(n == 1){
System.out.println(firstName+" "+lastName );
}
}
}
Output:
Enter the number: 1
Suresh Murapaka
Lab2.java
import java.util.Scanner;
public class Lab2 {
public static void main(String[] args) {
String firstName = "Suresh";
String lastName = "Murapaka";
Scanner scan = new Scanner(System.in);
System.out.print("Enter the number: ");
int n = scan.nextInt();
if(n == 1){
System.out.println(firstName+" "+lastName );
} else {
System.out.println("thanks!");
}
}
}
Output:
Enter the number: 2
thanks!
Lab3.java
import java.util.Scanner;
public class Lab3 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.print("Enter the number: ");
int n = scan.nextInt();
if(n < 0){
System.out.println("the number is negative" );
} else {
System.out.println("the number is positive");
}
}
}
Output:
Enter the number: -5
the number is negative
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.