Excercise Programs
Excercise Programs
Programs
Input in Java
Solutions to Unsolved Java Programs-
Question 1
In an election, there are candidates X and Y. On the election day, 80%
of the voters go for polling, out of which 60% vote for X. Write a
program to take the number of voters as input and calculate:
number of votes X get
number of votes Y get
import java.util.Scanner;
public class KboatPolling
{
public static void main(String args[]) {
For every natural number m>1; 2m, m2-1 and m2+1 form a
Pythagorean triplet. Write a program to input the value of 'm' through
console to display a 'Pythagorean Triplet'.
Sample Input: 3
Then 2m=6, m2-1=8 and m2+1=10
Thus 6, 8, 10 form a 'Pythagorean Triplet'.
import java.util.Scanner;
}
}
Output
Question 3
Write a program to input a number. Calculate its square root and cube
root. Finally, display the result by rounding it off.
Sample Input: 5
Square root of 5= 2.2360679
Rounded form= 2
Cube root of 5 = 1.7099759
Rounded form= 2
import java.util.Scanner;
System.out.print("Enter a: ");
int a = in.nextInt();
}
Conditional statements
in java