Keyboard input in Java and substitute variables

Asked 1 years ago, Updated 1 years ago, 52 views

I want to enter an integer value from the keyboard in Java and substitute it for a variable.
I'd like to enter test scores and write a code to display different documents for each score.

public class main {
  public static void main(String[]args) {

    int input = new java.util.Scanner(System.in).nextInt();

  }

  public static void point() {
    if (100 points) {
      System.out.println;
    } else if (from 70 to 99) {
      System.out.println();
    } else{
      System.out.println("Let's do our best"");
    }
  }
}

java

2022-09-30 21:42

1 Answers

In Java, enter an integer value from the keyboard and substitute it for a variable.

It's working.
The variable input is populated with integer values entered from the keyboard.
If you display the contents of input in System.out.println as shown below, you can see that it has been substituted.

int input=new java.util.Scanner(System.in).nextInt();
US>System.out.println("The value in input is '+input+"'.");

I'd like to enter test scores and write a code to display different documents for each score.

To display different documents for each score, you may want to pass arguments to the point method.
You can evaluate the value of input in if statements only by passing it with arguments.

The sample code below is designed to force compilation so that the logic of sentences such as if (100 points) does not cause compilation errors.

public class main {

    static final Boolean score of 100 = false;
    static final Boolean_70 to 99 = false;

    public static void main(String[]args) {
        int input = new java.util.Scanner(System.in).nextInt();
        US>System.out.println("The value in input is '+input+"'.");
        checkPoint(input);
        point();
    }

    public static void point() {
        if (100 points) {
            System.out.println("Sentence TBD");
        } else if (_70 to 99 points) {
            System.out.println();
        } else{
            System.out.println("Let's do our best"");
        }
    }

    /**
     * Code samples that work hard without using if statements
     * @paramp This is how you use the argument.
     */
    private static void checkPoint (intp)
    {
        intd=(int)(p/10);
        Strings;
        switch(d){
            case10:s = "Sentence TBD"; break;
            case9:case8:case7:s="???";break;
            default:s="Let's do our best";break;
        }
        System.out.println(s);
    }
}

The difference between the variable and the "string", how to use the if statement, how to use ==, and how to use & should have been suggested in the previous text, so you can use the checkPoint method to display the point argument.

Good luck.


2022-09-30 21:42

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.