Java Programming Practice Set , I have some questions for you guys and i hope you can solve all of the question if you are accessing my playlist from starting so lets get started guys.....
Question-1 : Write a program of sum of 4 digits and get the output with the help of the scanner class
Question-2 : Write a program to convert KM to Miles and then Miles to KM (1 KM = 0.61 Mile) and (1 Mile = 1.60 KM)
Question-3 : Write a program to enter your name and it will print
Namaste , <Your Name>
Question-4 : Write a program to find the square of the number and then you have to find the square root of that number.
Question-5 : Write a program to find the cube of the number and then you have to find the cube root of that number.
Question-6 : Write a program to solve this equation :
(1) ax^2+8y^2+10 , where X and Y should be entered by the help of scanner class
Question-7 : Find the Hypotenuse of the right angled triangle whose height is 3 Units and Base is 4 Units
Question-8 : If the length of the field is double that of the breadth of the field than find the
(1) Perimeter of the field
(2) Area of the Field
"Note This question can be done with the help of the scanner class"
Please Download the Notes PDF format by clicking here : Click Here
Code Snippet Of the Practice Set - 1:
package practice.set1;
import java.util.Scanner;
public class PracticeSet1 {
public static void main(String[] args) {
// Scanner class for all questions
Scanner ref=new Scanner(System.in);
// first question: Sum of 4 numbers
System.out.println("Enter 4 numbers ");
int firstnum = ref.nextInt();
int secondnum = ref.nextInt();
int thirdnum = ref.nextInt();
int fourthnum = ref.nextInt();
int totalsum = firstnum+secondnum+thirdnum+fourthnum;
System.out.println("The Sum of "+firstnum+","+secondnum+","+thirdnum+","+fourthnum+" is :"+totalsum);
// second question (Kilometer to miles and miles to kilometers)
// 1 kilometer = 0.62 miles
// 1 mile = 1.60 kilometers
System.out.println("Enter your input in Kilometers");
int kilometers = ref.nextInt();
// to miles conversion
float convert = kilometers*0.62f;
System.out.println(kilometers+" is equal to "+convert+" miles");
System.out.println("Enter your input in miles");
// to kilometer conversion
int miles = ref.nextInt();
float convert2 = miles*1.60f;
System.out.println(miles+"miles is equal to "+convert2+" kilometers");
// question number 3
System.out.println("Enter your name");
Scanner ref2=new Scanner(System.in);
String name = ref2.nextLine();
System.out.println("Namaste ,"+name);
// question number 4
// for getting square of a number = (a)^2= a*a
// for caculating square root
int number = ref.nextInt();
double var3 = Math.sqrt(number); //for getting square root
// for type casting double to integer
int var2 = (int)var3;
System.out.println("The square of "+number+" is "+number*number);
System.out.println("The square root of "+number+" is "+var2);
// question 5 : Cube and cuberoot finding
int number2 = ref.nextInt();
double var4 = Math.cbrt(number2); //for getting cube root
// for type casting double to integer
int var6 = (int)var4;
System.out.println("The cube of "+number2+" is "+number2*number2*number2);
System.out.println("The cube root of "+number2+" is "+var6);
// question 6 : equation solver 9X^2+8Y^3+10
Scanner ref3=new Scanner(System.in);
System.out.println("Enter the value of X ");
int x=ref3.nextInt();
System.out.println("Enter the value of Y ");
int y=ref3.nextInt();
int result = 9*x*x+8*y*y*y+10;
System.out.println("The solution of equation is "+result);
// question number 7: Pythagoras therom excersice
/*
(Hypo)^2 = (B)^2 + (H)^2
base = 4
height = 3
(hypo)^2 = (base)^2 + (height)^2
hypo = 16+9=25=5
*/
Scanner ref4=new Scanner(System.in);
System.out.println("Enter the height of the triangle ");
int height = ref4.nextInt();
System.out.println("Enter the base of the triangle ");
int base = ref4.nextInt();
double hypotenuse = Math.sqrt(height*height+base*base);
int convert3 = (int)hypotenuse;
System.out.println("The hypotenuse is of "+convert3+" unit ");
// question number 8 : problem sum
/*
breadth of the field = a
length of the field = 2*a
*/
Scanner ref5 = new Scanner(System.in);
System.out.print("Enter the breadth in meters ");
int breadth = ref5.nextInt();
int length = breadth*2;
// perimter of the rectangle is 2(L+B)
int perimeter = 2*length+2*breadth;
System.out.println("The perimeter of rectangle having "+length+" as length and breadth of "+breadth+" is "+perimeter);
// area of the rectangle is L*B
int area = length*breadth;
System.out.println("The area of rectangle having "+length+" as length and breadth of "+breadth+" is "+area);
}
}