Java Basic Activities: Getting the user's input



===============================
Code: 
===============================

import java.util.Scanner;

public class Test17_Pereda_Scanner {

public static void main(String [] args) {

Scanner input = new Scanner(System.in);

String name1;
String name2;

System.out.println("Enter Your Full Name:");
name1 = input.nextLine();

System.out.println("What is Your Last Name:");
name2 = input.nextLine();


System.out.println("\n\nYour full name:" +name1);
System.out.println("\n\n Your last name:" +name2);


input.close();


}
}

============================================

Get the user's integer input



import java.util.Scanner;

public class Test18_Pereda_Scannerint {

public static void main(String [] args) {   

Scanner input = new Scanner(System.in);

int num1, num2;

System.out.println("Enter two intergers:");

num1 = input.nextInt();
num2 = input.nextInt();

System.out.println("The number you entered: " + num1 + " and " +num2);

input.close();
     }

}


==================================================================

Get the user's integer input w/ double and float data type




==========================
Code
==========================
import java.util.Scanner;

public class Test19_Pereda_Scannerfloat {

public static void main(String [] args) {  

Scanner input = new Scanner(System.in);

float num1;
double num2;

System.out.println("Enter num1:");
num1 = input.nextFloat();

System.out.println("Enter num2:");
num2 = input.nextDouble();

System.out.println("\n\nThe number you entered: " + num1 + " and " +num2);

input.close();

}
}


=====================================================


Get the user's string input

======================================================




import java.util.Scanner;

public class Test20_Pereda_Challenge {

public static void main(String [] args) {

Scanner input = new Scanner(System.in);

String name1;
String name2;
String name3;
String name4;
String name5;
String name6;
String name7;
String name8;
String name9;
String name10;



System.out.println("Enter your Firstname:");
name1 = input.nextLine();

System.out.println("Enter your Lastname:");
name2 = input.nextLine();

System.out.println("Enter your age:");
name3 = input.nextLine();

System.out.println("Enter your birthdate:");
name4 = input.nextLine();

System.out.println("Enter your address:");
name5 = input.nextLine();

System.out.println("Enter your course:");
name6 = input.nextLine();

System.out.println("Enter your Year and Section:");
name7 = input.nextLine();

System.out.println("Enter the Subject Code:");
name8 = input.nextLine();

System.out.println("Enter the Subject Title:");
name9 = input.nextLine();

System.out.println("Enter the fullname of your Instructor in java:");
name10 = input.nextLine();



System.out.println("=========================");
System.out.println("Firstname:" +name1);
System.out.println("Lastname:" +name2);
System.out.println("Age:" +name3);
System.out.println("Birthdate:" +name4);
System.out.println("Address:" +name5);
System.out.println("Course:" +name6);
System.out.println("Year and Section:" +name7);
System.out.println("Subject Code:" +name8);
System.out.println("Subject Title:" +name9);
System.out.println("Name of Instructor in java:" +name10);
System.out.println("=======================");


input.close();

}

}



=====================================================

Get the user's integer input and display the sum

=======================================================


=============================
Code: 
====================

import java.util.Scanner;

public class Test21_Pereda_operator {

public static void main(String [] args) {

Scanner input = new Scanner(System.in);

int num1, num2, sum;

System.out.println("Enter First num: ");
num1 = input.nextInt();

System.out.println("Enter Second num :");
num2 = input.nextInt();

sum = num1 + num2;

System.out.println("\n\n\nThe sum of the first and 2nd numbers:" + sum);



input.close();

}

}

==============================================

Get the user's integer input and display the sum , difference, product and quotient of the two integers



=====================
Code:
=====================


import java.util.Scanner;

public class Test22_Pereda_Challenge {

public static void main(String [] args) {
Scanner input = new Scanner(System.in);
int num1, num2, sum, diff, product, qou;
System.out.println("Enter First num: ");
num1 = input.nextInt();
System.out.println("Enter Second num :");
num2 = input.nextInt();
sum = num1 + num2;
diff = num1 - num2;
product = num1 * num2;
qou = num1 / num2;
System.out.println("\n\nThe sum of the first and 2nd numbers:" + sum);
System.out.println("The difference of the first and 2nd numbers:" + diff);
System.out.println("The product of the first and 2nd numbers:" + product);
System.out.println("The quotient of the first and 2nd numbers:" + qou);
input.close();
}


}

==============================================





















































Walang komento:

Mag-post ng isang Komento