Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Accept Integer only in if else statement

package shipcost;

import java.io.*;

//Your class should be ShipCost (All words starting with uppercase)
public class ShipCost {

    public static void main(String[] args) {

    //Declare and initialize your variables first (with invalid values for your program)
    double input = -1;
    double total = 0;
    String s1 = null;

    //This will loop to prompt the user until the input is correct
    while (true) {

        try {

            //try to execute the folowing lines
            s1 = getInput("enter the item price");
            input = Integer.parseInt(s1);

            //If everything went fine, break the loop and move on.
            break;

        } catch (NumberFormatException e) {

            //If the method Integer.parseInt throws the exception, cathc and print the message.
            System.out.println("Not a valid input, please try again.");
        }
    }


    if (input < 100) {

        //What is this line exactly doing?
        //double total = input += input * .02;

        //This is better. If input less than 100, charge 2% over the price.
        total = input * 1.02;

        System.out.println(total);

        //How can you return something from a void method (in this case main).
        //The statement below will not compile
        //return stdin.readLine();

    } else {

        //If greater than or equal to 100, do not charge shiping.
        total = input;
        System.out.println(total);

    }

}

    private static String getInput(String prompt) {

        //Comment your code for your own good, it makes more readable and helps you in future ref.
        BufferedReader stdin = new BufferedReader(
                new InputStreamReader(System.in));

        //Separate your line in chunks for commenting.
        System.out.print(prompt);
        System.out.flush();

        try {
            return stdin.readLine();
        } catch (Exception e) {
            return "Error: " + e.getMessage();
        }
    }

}
Comment

Accept Integer only in if else statement

package shipcost;

import java.io.*;

//Your class should be ShipCost (All words starting with uppercase)
public class ShipCost {

    public static void main(String[] args) {

    //Declare and initialize your variables first (with invalid values for your program)
    double input = -1;
    double total = 0;
    String s1 = null;

    //This will loop to prompt the user until the input is correct
    while (true) {

        try {
            //try to execute the folowing lines
            s1 = getInput("enter the item price");
            input = Integer.parseInt(s1);

            //If everything went fine, break the loop and move on.
            break;

        } catch (NumberFormatException e) {

            //If the method Integer.parseInt throws the exception, cathc and print the message.
            System.out.println("Not a valid input, please try again.");
        }
    }


    if (input < 100) {

        //What is this line exactly doing?
        //double total = input += input * .02;

        //This is better. If input less than 100, charge 2% over the price.
        total = input * 1.02;

        System.out.println(total);

        //How can you return something from a void method (in this case main).
        //The statement below will not compile
        //return stdin.readLine();

    } else {

        //If greater than or equal to 100, do not charge shiping.
        total = input;
        System.out.println(total);

    }

}

    private static String getInput(String prompt) {

        //Comment your code for your own good, it makes more readable and helps you in future ref.
        BufferedReader stdin = new BufferedReader(
                new InputStreamReader(System.in));

        //Separate your line in chunks for commenting.
        System.out.print(prompt);
        System.out.flush();

        try {
            return stdin.readLine();
        } catch (Exception e) {
            return "Error: " + e.getMessage();
        }
    }

}
Comment

Accept Integer only in if else statement

package shipcost;

import java.io.*;

//Your class should be ShipCost (All words starting with uppercase)
public class ShipCost {

    public static void main(String[] args) {

    //Declare and initialize your variables first (with invalid values for your program)
    double input = -1;
    double total = 0;
    String s1 = null;

    //This will loop to prompt the user until the input is correct
    while (true) {

        try {

            //try to execute the folowing lines
            s1 = getInput("enter the item price");
            input = Integer.parseInt(s1);

            //If everything went fine, break the loop and move on.
            break;

        } catch (NumberFormatException e) {

            //If the method Integer.parseInt throws the exception, cathc and print the message.
            System.out.println("Not a valid input, please try again.");
        }
    }


    if (input < 100) {

        //What is this line exactly doing?
        //double total = input += input * .02;

        //This is better. If input less than 100, charge 2% over the price.
        total = input * 1.02;

        System.out.println(total);

        //How can you return something from a void method (in this case main).
        //The statement below will not compile
        //return stdin.readLine();

    } else {

        //If greater than or equal to 100, do not charge shiping.
        total = input;
        System.out.println(total);

    }

}

    private static String getInput(String prompt) {

        //Comment your code for your own good, it makes more readable and helps you in future ref.
        BufferedReader stdin = new BufferedReader(
                new InputStreamReader(System.in));

        //Separate your line in chunks for commenting.
        System.out.print(prompt);
        System.out.flush();

        try {
            return stdin.readLine();
        } catch (Exception e) {
            return "Error: " + e.getMessage();
        }
    }

}
Comment

Accept Integer only in if else statement

package shipcost;

import java.io.*;

//Your class should be ShipCost (All words starting with uppercase)
public class ShipCost {

    public static void main(String[] args) {

    //Declare and initialize your variables first (with invalid values for your program)
    double input = -1;
    double total = 0;
    String s1 = null;

    //This will loop to prompt the user until the input is correct
    while (true) {

        try {

            //try to execute the folowing lines
            s1 = getInput("enter the item price");
            input = Integer.parseInt(s1);

            //If everything went fine, break the loop and move on.
            break;

        } catch (NumberFormatException e) {

            //If the method Integer.parseInt throws the exception, cathc and print the message.
            System.out.println("Not a valid input, please try again.");
        }
    }


    if (input < 100) {

        //What is this line exactly doing?
        //double total = input += input * .02;

        //This is better. If input less than 100, charge 2% over the price.
        total = input * 1.02;

        System.out.println(total);

        //How can you return something from a void method (in this case main).
        //The statement below will not compile
        //return stdin.readLine();

    } else {

        //If greater than or equal to 100, do not charge shiping.
        total = input;
        System.out.println(total);

    }

}

    private static String getInput(String prompt) {

        //Comment your code for your own good, it makes more readable and helps you in future ref.
        BufferedReader stdin = new BufferedReader(
                new InputStreamReader(System.in));

        //Separate your line in chunks for commenting.
        System.out.print(prompt);
        System.out.flush();

        try {
            return stdin.readLine();
        } catch (Exception e) {
            return "Error: " + e.getMessage();
        }
    }

}
Comment

Accept Integer only in if else statement

package shipcost;

import java.io.*;

//Your class should be ShipCost (All words starting with uppercase)
public class ShipCost {

    public static void main(String[] args) {

    //Declare and initialize your variables first (with invalid values for your program)
    double input = -1;
    double total = 0;
    String s1 = null;

    //This will loop to prompt the user until the input is correct
    while (true) {

        try {

            //try to execute the folowing lines
            s1 = getInput("enter the item price");
            input = Integer.parseInt(s1);

            //If everything went fine, break the loop and move on.
            break;

        } catch (NumberFormatException e) {

            //If the method Integer.parseInt throws the exception, cathc and print the message.
            System.out.println("Not a valid input, please try again.");
        }
    }


    if (input < 100) {

        //What is this line exactly doing?
        //double total = input += input * .02;

        //This is better. If input less than 100, charge 2% over the price.
        total = input * 1.02;

        System.out.println(total);

        //How can you return something from a void method (in this case main).
        //The statement below will not compile
        //return stdin.readLine();

    } else {

        //If greater than or equal to 100, do not charge shiping.
        total = input;
        System.out.println(total);

    }

}

    private static String getInput(String prompt) {

        //Comment your code for your own good, it makes more readable and helps you in future ref.
        BufferedReader stdin = new BufferedReader(
                new InputStreamReader(System.in));

        //Separate your line in chunks for commenting.
        System.out.print(prompt);
        System.out.flush();

        try {
            return stdin.readLine();
        } catch (Exception e) {
            return "Error: " + e.getMessage();
        }
    }

}
Comment

Accept Integer only in if else statement

package shipcost;

import java.io.*;

//Your class should be ShipCost (All words starting with uppercase)
public class ShipCost {

    public static void main(String[] args) {

    //Declare and initialize your variables first (with invalid values for your program)
    double input = -1;
    double total = 0;
    String s1 = null;

    //This will loop to prompt the user until the input is correct
    while (true) {

        try {

            //try to execute the folowing lines
            s1 = getInput("enter the item price");
            input = Integer.parseInt(s1);

            //If everything went fine, break the loop and move on.
            break;

        } catch (NumberFormatException e) {

            //If the method Integer.parseInt throws the exception, cathc and print the message.
            System.out.println("Not a valid input, please try again.");
        }
    }


    if (input < 100) {

        //What is this line exactly doing?
        //double total = input += input * .02;

        //This is better. If input less than 100, charge 2% over the price.
        total = input * 1.02;

        System.out.println(total);

        //How can you return something from a void method (in this case main).
        //The statement below will not compile
        //return stdin.readLine();

    } else {

        //If greater than or equal to 100, do not charge shiping.
        total = input;
        System.out.println(total);

    }

}

    private static String getInput(String prompt) {

        //Comment your code for your own good, it makes more readable and helps you in future ref.
        BufferedReader stdin = new BufferedReader(
                new InputStreamReader(System.in));

        //Separate your line in chunks for commenting.
        System.out.print(prompt);
        System.out.flush();

        try {
            return stdin.readLine();
        } catch (Exception e) {
            return "Error: " + e.getMessage();
        }
    }

}
Comment

Accept Integer only in if else statement

package shipcost;

import java.io.*;

//Your class should be ShipCost (All words starting with uppercase)
public class ShipCost {

    public static void main(String[] args) {

    //Declare and initialize your variables first (with invalid values for your program)
    double input = -1;
    double total = 0;
    String s1 = null;

    //This will loop to prompt the user until the input is correct
    while (true) {

        try {

            //try to execute the folowing lines
            s1 = getInput("enter the item price");
            input = Integer.parseInt(s1);

            //If everything went fine, break the loop and move on.
            break;

        } catch (NumberFormatException e) {

            //If the method Integer.parseInt throws the exception, cathc and print the message.
            System.out.println("Not a valid input, please try again.");
        }
    }


    if (input < 100) {

        //What is this line exactly doing?
        //double total = input += input * .02;

        //This is better. If input less than 100, charge 2% over the price.
        total = input * 1.02;

        System.out.println(total);

        //How can you return something from a void method (in this case main).
        //The statement below will not compile
        //return stdin.readLine();

    } else {

        //If greater than or equal to 100, do not charge shiping.
        total = input;
        System.out.println(total);

    }

}

    private static String getInput(String prompt) {

        //Comment your code for your own good, it makes more readable and helps you in future ref.
        BufferedReader stdin = new BufferedReader(
                new InputStreamReader(System.in));

        //Separate your line in chunks for commenting.
        System.out.print(prompt);
        System.out.flush();

        try {
            return stdin.readLine();
        } catch (Exception e) {
            return "Error: " + e.getMessage();
        }
    }

}
Comment

Accept Integer only in if else statement

package shipcost;

import java.io.*;

//Your class should be ShipCost (All words starting with uppercase)
public class ShipCost {

    public static void main(String[] args) {

    //Declare and initialize your variables first (with invalid values for your program)
    double input = -1;
    double total = 0;
    String s1 = null;

    //This will loop to prompt the user until the input is correct
    while (true) {

        try {
            //try to execute the folowing lines
            s1 = getInput("enter the item price");
            input = Integer.parseInt(s1);

            //If everything went fine, break the loop and move on.
            break;

        } catch (NumberFormatException e) {

            //If the method Integer.parseInt throws the exception, cathc and print the message.
            System.out.println("Not a valid input, please try again.");
        }
    }


    if (input < 100) {

        //What is this line exactly doing?
        //double total = input += input * .02;

        //This is better. If input less than 100, charge 2% over the price.
        total = input * 1.02;

        System.out.println(total);

        //How can you return something from a void method (in this case main).
        //The statement below will not compile
        //return stdin.readLine();

    } else {

        //If greater than or equal to 100, do not charge shiping.
        total = input;
        System.out.println(total);

    }

}

    private static String getInput(String prompt) {

        //Comment your code for your own good, it makes more readable and helps you in future ref.
        BufferedReader stdin = new BufferedReader(
                new InputStreamReader(System.in));

        //Separate your line in chunks for commenting.
        System.out.print(prompt);
        System.out.flush();

        try {
            return stdin.readLine();
        } catch (Exception e) {
            return "Error: " + e.getMessage();
        }
    }

}
Comment

Accept Integer only in if else statement

package shipcost;

import java.io.*;

//Your class should be ShipCost (All words starting with uppercase)
public class ShipCost {

    public static void main(String[] args) {

    //Declare and initialize your variables first (with invalid values for your program)
    double input = -1;
    double total = 0;
    String s1 = null;

    //This will loop to prompt the user until the input is correct
    while (true) {

        try {

            //try to execute the folowing lines
            s1 = getInput("enter the item price");
            input = Integer.parseInt(s1);

            //If everything went fine, break the loop and move on.
            break;

        } catch (NumberFormatException e) {

            //If the method Integer.parseInt throws the exception, cathc and print the message.
            System.out.println("Not a valid input, please try again.");
        }
    }


    if (input < 100) {

        //What is this line exactly doing?
        //double total = input += input * .02;

        //This is better. If input less than 100, charge 2% over the price.
        total = input * 1.02;

        System.out.println(total);

        //How can you return something from a void method (in this case main).
        //The statement below will not compile
        //return stdin.readLine();

    } else {

        //If greater than or equal to 100, do not charge shiping.
        total = input;
        System.out.println(total);

    }

}

    private static String getInput(String prompt) {

        //Comment your code for your own good, it makes more readable and helps you in future ref.
        BufferedReader stdin = new BufferedReader(
                new InputStreamReader(System.in));

        //Separate your line in chunks for commenting.
        System.out.print(prompt);
        System.out.flush();

        try {
            return stdin.readLine();
        } catch (Exception e) {
            return "Error: " + e.getMessage();
        }
    }

}
Comment

Accept Integer only in if else statement

package shipcost;

import java.io.*;

//Your class should be ShipCost (All words starting with uppercase)
public class ShipCost {

    public static void main(String[] args) {

    //Declare and initialize your variables first (with invalid values for your program)
    double input = -1;
    double total = 0;
    String s1 = null;

    //This will loop to prompt the user until the input is correct
    while (true) {

        try {

            //try to execute the folowing lines
            s1 = getInput("enter the item price");
            input = Integer.parseInt(s1);

            //If everything went fine, break the loop and move on.
            break;

        } catch (NumberFormatException e) {

            //If the method Integer.parseInt throws the exception, cathc and print the message.
            System.out.println("Not a valid input, please try again.");
        }
    }


    if (input < 100) {

        //What is this line exactly doing?
        //double total = input += input * .02;

        //This is better. If input less than 100, charge 2% over the price.
        total = input * 1.02;

        System.out.println(total);

        //How can you return something from a void method (in this case main).
        //The statement below will not compile
        //return stdin.readLine();

    } else {

        //If greater than or equal to 100, do not charge shiping.
        total = input;
        System.out.println(total);

    }

}

    private static String getInput(String prompt) {

        //Comment your code for your own good, it makes more readable and helps you in future ref.
        BufferedReader stdin = new BufferedReader(
                new InputStreamReader(System.in));

        //Separate your line in chunks for commenting.
        System.out.print(prompt);
        System.out.flush();

        try {
            return stdin.readLine();
        } catch (Exception e) {
            return "Error: " + e.getMessage();
        }
    }

}
Comment

Accept Integer only in if else statement

package shipcost;

import java.io.*;

//Your class should be ShipCost (All words starting with uppercase)
public class ShipCost {

    public static void main(String[] args) {

    //Declare and initialize your variables first (with invalid values for your program)
    double input = -1;
    double total = 0;
    String s1 = null;

    //This will loop to prompt the user until the input is correct
    while (true) {

        try {

            //try to execute the folowing lines
            s1 = getInput("enter the item price");
            input = Integer.parseInt(s1);

            //If everything went fine, break the loop and move on.
            break;

        } catch (NumberFormatException e) {

            //If the method Integer.parseInt throws the exception, cathc and print the message.
            System.out.println("Not a valid input, please try again.");
        }
    }


    if (input < 100) {

        //What is this line exactly doing?
        //double total = input += input * .02;

        //This is better. If input less than 100, charge 2% over the price.
        total = input * 1.02;

        System.out.println(total);

        //How can you return something from a void method (in this case main).
        //The statement below will not compile
        //return stdin.readLine();

    } else {

        //If greater than or equal to 100, do not charge shiping.
        total = input;
        System.out.println(total);

    }

}

    private static String getInput(String prompt) {

        //Comment your code for your own good, it makes more readable and helps you in future ref.
        BufferedReader stdin = new BufferedReader(
                new InputStreamReader(System.in));

        //Separate your line in chunks for commenting.
        System.out.print(prompt);
        System.out.flush();

        try {
            return stdin.readLine();
        } catch (Exception e) {
            return "Error: " + e.getMessage();
        }
    }

}
Comment

Accept Integer only in if else statement

package shipcost;

import java.io.*;

//Your class should be ShipCost (All words starting with uppercase)
public class ShipCost {

    public static void main(String[] args) {

    //Declare and initialize your variables first (with invalid values for your program)
    double input = -1;
    double total = 0;
    String s1 = null;

    //This will loop to prompt the user until the input is correct
    while (true) {

        try {

            //try to execute the folowing lines
            s1 = getInput("enter the item price");
            input = Integer.parseInt(s1);

            //If everything went fine, break the loop and move on.
            break;

        } catch (NumberFormatException e) {

            //If the method Integer.parseInt throws the exception, cathc and print the message.
            System.out.println("Not a valid input, please try again.");
        }
    }


    if (input < 100) {

        //What is this line exactly doing?
        //double total = input += input * .02;

        //This is better. If input less than 100, charge 2% over the price.
        total = input * 1.02;

        System.out.println(total);

        //How can you return something from a void method (in this case main).
        //The statement below will not compile
        //return stdin.readLine();

    } else {

        //If greater than or equal to 100, do not charge shiping.
        total = input;
        System.out.println(total);

    }

}

    private static String getInput(String prompt) {

        //Comment your code for your own good, it makes more readable and helps you in future ref.
        BufferedReader stdin = new BufferedReader(
                new InputStreamReader(System.in));

        //Separate your line in chunks for commenting.
        System.out.print(prompt);
        System.out.flush();

        try {
            return stdin.readLine();
        } catch (Exception e) {
            return "Error: " + e.getMessage();
        }
    }

}
Comment

Accept Integer only in if else statement

package shipcost;

import java.io.*;

//Your class should be ShipCost (All words starting with uppercase)
public class ShipCost {

    public static void main(String[] args) {

    //Declare and initialize your variables first (with invalid values for your program)
    double input = -1;
    double total = 0;
    String s1 = null;

    //This will loop to prompt the user until the input is correct
    while (true) {

        try {

            //try to execute the folowing lines
            s1 = getInput("enter the item price");
            input = Integer.parseInt(s1);

            //If everything went fine, break the loop and move on.
            break;

        } catch (NumberFormatException e) {

            //If the method Integer.parseInt throws the exception, cathc and print the message.
            System.out.println("Not a valid input, please try again.");
        }
    }


    if (input < 100) {

        //What is this line exactly doing?
        //double total = input += input * .02;

        //This is better. If input less than 100, charge 2% over the price.
        total = input * 1.02;

        System.out.println(total);

        //How can you return something from a void method (in this case main).
        //The statement below will not compile
        //return stdin.readLine();

    } else {

        //If greater than or equal to 100, do not charge shiping.
        total = input;
        System.out.println(total);

    }

}

    private static String getInput(String prompt) {

        //Comment your code for your own good, it makes more readable and helps you in future ref.
        BufferedReader stdin = new BufferedReader(
                new InputStreamReader(System.in));

        //Separate your line in chunks for commenting.
        System.out.print(prompt);
        System.out.flush();

        try {
            return stdin.readLine();
        } catch (Exception e) {
            return "Error: " + e.getMessage();
        }
    }

}
Comment

PREVIOUS NEXT
Code Example
Java :: java notnull returns null 
Java :: best wireless headphoenes under 200 
Java :: how do you create a txt file in java 
Java :: find center of screen graphic g 
Java :: java this keyword 
Java :: View get text android Close 
Java :: what are construtcor java 
Java :: print java object inherited classes 
Java :: How to code the Fibonacci Sequence using simple iterative loops java 
Java :: java get the closest pair to a given sum in two arrays 
Java :: get string match percentage java 
Java :: variables en java 
Java :: In similar fashion we will use (RIGHT – SHIFT) to retrieve bits from val 6 at a time 
Java :: sealed class in kotlin example 
Java :: mock dynamodb unit 
Java :: java pebble replacestart 
Java :: customize the androidx.appcompat.widget.SearchView site:stackoverflow.com 
Java :: text blocks 
Java :: demo application using stomp js and node js 
Java :: grepper editor 
Java :: ways to add properties to Bean Spring 
Java :: spigot check if inventory is empty 
Java :: Static And Public Methods 
Java :: how to divide coloumns in a text file into seperate arrays in java 
Java :: How to Register a Custom Auto-Configuration? 
Java :: SpringBootStarter maven dependency 
Java :: run java bytecode 
Java :: infinite loop in java 
Java :: httpsession vs cookie servlet 
Java :: Program to read base and power and then calculate result of that expression using recursion in java 
ADD CONTENT
Topic
Content
Source link
Name
3+6 =