0% found this document useful (0 votes)
3 views6 pages

Ass 1

The document outlines a series of programming tasks in Java, including reading user input, performing arithmetic operations, and printing output. It also includes questions about the expected output of specific code snippets based on user input. Additionally, it requests a program to gather user credentials and personal information using the Scanner class.

Uploaded by

manasi date
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views6 pages

Ass 1

The document outlines a series of programming tasks in Java, including reading user input, performing arithmetic operations, and printing output. It also includes questions about the expected output of specific code snippets based on user input. Additionally, it requests a program to gather user credentials and personal information using the Scanner class.

Uploaded by

manasi date
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Q1.

) Write a program for the following:

-> Declare an integer variable num.

-> Read the value from the user.

-> Print it's square.

Q2.) Complete the given program to create a simple calculator that performs addition and subtraction.

-> Declare 2 integer variables a and b

-> Initialize the variables a and b with two user inputs.

-> Declare an integer variable sum and assign the value of addition of a and b to it.

-> Declare another integer variable diff and assign the value of subtraction of a and b to it.

-> Output sum and diff to the console on separate lines with the same message as given in sample
output.
Q3.) Write a program which does the following:
-> Declare a string variable x.

-> Accept a text user input the name of the user - and store it in the variable x.

-> Output and print to the console "Hello" before the user defined name.

-> Remember to add a space between "Hello" and x.

Q4.) What will be the output of this code, if the user enters Ram?

class Sample {

public static void main(String[] args) {

Scanner read = new Scanner(System.in);

String sc = read.nextLine();

System.out.println("Your name is: " + sc);

}
}

=It is not showing output not showing Error. Program continues its execution till close the program.

Q5.) What will be the output of this code, if the user enters

5 and 9 when asked for input for a and b respectively?

class Sample {

public static void main(String[] args) {

Scanner read = new Scanner(System.in);

int a = read.nextInt();

int b = read.nextInt();

int c = a + 2;

int d = c + b;

System.out.println(d);

}
Q6.) Write a java program that uses the Scanner class to get userID, password, name and age from the
user input?

You might also like