0% found this document useful (0 votes)
14 views1 page

Java Basics Internship Tasklist

The document outlines a task list for an intern at XploCode Infotech Private Limited focusing on Java basics. It includes tasks such as declaring variables, calculating totals, and obtaining user input for personal and book details. Each task specifies expected outputs to guide the intern's coding exercises.

Uploaded by

Surya Dharshini
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views1 page

Java Basics Internship Tasklist

The document outlines a task list for an intern at XploCode Infotech Private Limited focusing on Java basics. It includes tasks such as declaring variables, calculating totals, and obtaining user input for personal and book details. Each task specifies expected outputs to guide the intern's coding exercises.

Uploaded by

Surya Dharshini
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

XploCode Infotech Private Limited

Intern - Java Basics Tasklist


Day 1
1.​ Declare variables for a person’s name, age, and salary. Print all values.
2.​ Declare variables for three subject marks. Calculate and print the total.
3.​ My name is Rani
My age is 23
My height is 5.4
Write code using variables to produce the above output.
4.​ Task: Get name, roll number, and department from the user. Display them.
Expected Output :
Enter name: Rahul
Enter roll number: 101
Enter department: CSE
STUDENT DETAILS
***********************
Student Name: Rahul
Roll Number: 101
Department: CSE
5.​ Task: Get book title, author, and number of pages. Display them.
Expected Output :
Enter book title: Java Basics
Enter author: James
Enter pages: 300
Book Details
~~~~~~~~~
Title​ ​ :​ Java Basics
Author​ :​ James
Pages​ :​ 300

Common questions

Powered by AI

In Java, you declare variables using data types that match the kind of value being stored. For a person's name, you would use a String: String name = "Rani";. For age and height, you would use int and double respectively: int age = 23; double height = 5.4;. To display these values, you use the System.out.println() method: System.out.println("My name is " + name); System.out.println("My age is " + age); System.out.println("My height is " + height)

To ensure all user inputs are correctly received for book details in Java, use the Scanner class to read each input separately. Import java.util.Scanner; and create a Scanner object: Scanner input = new Scanner(System.in);. Prompt the user for each item: String title = input.nextLine(); String author = input.nextLine(); int pages = input.nextInt();. Use input.nextLine() for Strings to ensure you read full lines of text, which prevents skipping issues when reading mixed data types. System.out.println() can then display the inputs: System.out.println("Book Title: " + title); System.out.println("Author: " + author); System.out.println("Pages: " + pages)

To output a formatted display in Java, especially for student details, use formatted strings with System.out.printf() or String.format(). For instance: System.out.printf("STUDENT DETAILS \n***********************\nStudent Name: %s\nRoll Number: %d\nDepartment: %s\n", name, rollNumber, department);. This approach allows you to control the format and layout, ensuring consistent spacing and alignment. It's particularly useful for tabulated data and when including variables in a specific pattern.

To input and display a student's information in Java, you can use the Scanner class to read input from the user. First, import java.util.Scanner; and create a Scanner object: Scanner input = new Scanner(System.in);. Then, prompt the user for input and assign it to variables: String name = input.nextLine(); int rollNumber = input.nextInt(); String department = input.next(); Finally, print the information using System.out.println(): System.out.println("Student Name: " + name); System.out.println("Roll Number: " + rollNumber); System.out.println("Department: " + department)

To calculate the sum of three subject marks in Java, declare three integer variables for the marks: int mark1, mark2, mark3;. Then, calculate the total: int total = mark1 + mark2 + mark3;. Display the result using: System.out.println("Total marks: " + total);. When choosing data types, consider the range of values. If marks can be fractional or very large, you might need to use double or long. However, for typical integer marks within a standard range, int is appropriate.

In Java, best practices for naming variables include using descriptive names that convey the variable’s purpose, following camelCase convention, and starting with a lowercase letter. For personal data like name, age, and salary, use names like "personName", "personAge", and "personSalary". These names suggest what data the variable holds, improving readability and maintenance. Avoid abbreviations and ensure names are not too lengthy or complex. Reserve uppercase names for constants .

You might also like