Showing posts with label java elementary programming. Show all posts
Showing posts with label java elementary programming. Show all posts

Sunday, 5 November 2017

java simple project runway lenght



Write a program that prompts the user to enter v in meters/second (m/s) and the
acceleration a in meters/second squared (m/s2), and displays the minimum runway
length
Description:
 By using formula    length =/2a
Solution
import java.util.*;
public class Message {
 public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
float a,v;
System.out.println("Enter the acceleration");
a=in.nextFloat();
System.out.println("Enter the velocity");
v=in.nextFloat();
System.out.println("The minimum lenght of runway is "+((v*v)/(2*a)));
}
}
Output:
                     

java simple project



Write a program that calculates the energy needed to heat water from an initial temperature to a final temperature. Your program should prompt the user to enter the amount of water in kilograms and the initial and final temperatures of the water. The formula to compute the energy is
Q = M * (finalTemperature – initialTemperature) * 4184
Description:
where M is the weight of water in kilograms, temperatures are in degrees Celsius,
and energy Q is measured in joules
Solution
import java.util.*;
public class Message {
 public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
float M,initialTemp,finalTemp;
System.out.println("Enter the amount of water in kilogram");
M=in.nextFloat();
System.out.println("Enter the initial temperature");
initialTemp=in.nextFloat();
System.out.println("Enter the final temperature");
finalTemp=in.nextFloat();
System.out.println("The energy needed is"+(M*(finalTemp-initialTemp)*4184));
}
}

Output:

java program that reverse the number without using loop



Write a program that reverse a number of five elements 10000 for example user enter 1234 9it display 43219
Description:
Using % operator and multiplying by 10:
Solution
import java.util.*;
public class Message {
 public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
   int num,sum=0;
   System.out.println("Enter a number of five element");
   num=in.nextInt();
    sum=sum*10+num%10;
   num/=10;
  
   sum=sum*10+num%10;
   num/=10;
    sum=sum*10+num%10;
   num/=10;
    sum=sum*10+num%10;
   num/=10;
    sum=sum*10+num%10;
 
   System.out.println("The reverse is  ="+sum);
 
 }
}
Output:
                   

java very difficult programming



Write a program that reads an integer between 0 and
10000 and adds all the digits in the integer. For example, if an integer is 932, the
sum of all its digits is 14.
Description:
Use the % operator to extract digits, and use the / operator to remove the
extracted digit. For instance, 932 % 10 = 2 and 932 / 10 = 93.
Solution
import java.util.*;
public class Message {
 public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
   int num,sum=0;
   System.out.println("Enter the mass in pound");
   num=in.nextInt();
   sum+=num%10;
   num/=10;
   sum+=num%10;
   num/=10;
   sum+=num%10;
   num/=10;
   sum+=num%10;
   num/=10;
   sum+=num%10;
   num/=10;
   System.out.println("The sum of all the element is ="+sum);
 
 }
}

Output: