Professional Documents
Culture Documents
Example 2: Program To Find Largest Number Among Three Numbers Using Nested If
Example 2: Program To Find Largest Number Among Three Numbers Using Nested If
import java.util.*;
public class Exercise53 {
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Input the first number : ");
int x = in.nextInt();
System.out.print("Input the second number: ");
int y = in.nextInt();
System.out.print("Input the third number : ");
int z = in.nextInt();
System.out.print("The result is: "+test(x, y, z,true));
System.out.print("\n");
}
class stringToint {
public static void main( String args[] ) {
String str = "1000";
int num = Integer.parseInt(str);
System.out.println(num);
}
}
class stringToInteger {
public static void main( String args[] ) {
String str = "1000";
Integer num = Integer.valueOf(str);
System.out.println(num);
}
}
Note: If the string contains letters along with numbers the function will return
an exception in this case, as shown in the code below.
class stringToInteger {
public static void main( String args[] ) {
String str = "100A0";
Integer num = Integer.valueOf(str);
System.out.println(num);
}
}
5)eligibility to vote
ava voting program
In this chapter of java programs tutorial, our task is to:
accept age of the voter and
verify whether he or she is eligible to vote or not. (age should be 18 or greater)
Given below is a java voting program that checks if person is eligible to vote or not. Here we
have considered that a person is eligible to vote once he attains age of 18 years.
If person is currently not eligible to vote at present then calculate the years after which the
person can cast vote.
package TIHIfElsePrograms;
import java.util.Scanner;
if(age>18){
System.out.println("Welcome to vote");
}else{
int shortBy = (18 - age);
System.out.println("Sorry, you can't vote now! You can
vote after :"+ shortBy + " years");
}