0% found this document useful (0 votes)
12 views

Java Labwork2

This document contains instructions for 4 programming questions. Question 1 asks to write a program that reads in a float, double, string, and integer from user input and prints them out. Question 2 asks to write a program that reads in two integers, calculates their difference, and prints it. Question 3 asks to read in 3 integers and print them in reverse order. Question 4 asks to read in 5 integers, calculate their remainder when divided by 8, and print the results.

Uploaded by

admin
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)
12 views

Java Labwork2

This document contains instructions for 4 programming questions. Question 1 asks to write a program that reads in a float, double, string, and integer from user input and prints them out. Question 2 asks to write a program that reads in two integers, calculates their difference, and prints it. Question 3 asks to read in 3 integers and print them in reverse order. Question 4 asks to read in 5 integers, calculate their remainder when divided by 8, and print the results.

Uploaded by

admin
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
You are on page 1/ 2

Computer Programming I CPE 1120101- Labwork 2 2022, Fall

Question 1
Write a Java program to read a floating point number, a double value, a string and an integer.
Then, output them by running the given program at below.
Note: import java.util.Scanner; at the beginning of your program.
Scanner input = new Scanner(System.in);
// Getting float input
System.out.print("Enter float: ");
float myFloat = input.nextFloat();
System.out.println("Float entered = " + myFloat);
// Getting double input
System.out.print("Enter double: ");
double myDouble = input.nextDouble();
System.out.println("Double entered = " + myDouble);
// Getting String input
System.out.print("Enter text: ");
String myString = input.next();
System.out.println("Text entered = " + myString);
System.out.print("Enter integer: ");
int myInt = input.nextInt();
System.out.println("Integer entered = " + myInt);

Question 2
Write a Java program to read 2 integer numbers and output the difference between them on
the screen.
Sample Output
Please enter first integer: 41
Please enter second integer: 11
Difference of the numbers is: 30
Computer Programming I CPE 1120101- Labwork 2 2022, Fall

Question 3
Write a Java program to read 3 integer numbers and output them in the reverse order.
Sample Output
Please enter three numbers: 5 10 15
Your numbers are 15 10 5

Question 4
Write a Java program which asks the user to input five integers and displays their remainder
from 8.
Sample Output
Enter five integers: 17 35 8 20 47
Result: 1 3 0 4 7

You might also like