G
G
gleb shtraus2020-10-02 20:48:07
Java
gleb shtraus, 2020-10-02 20:48:07

Why does 5 times 5 give 251?

import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.print("Input a number: ");
        int a = in.nextInt();
        System.out.print("Input a number: ");
        int b= in.nextInt();

        System.out.println("Введите действия с числами\n 1.сложить\n 2.вычесть \n 3.Умножить \n 4.Поделить");
int t=in.nextInt();
switch (t) {
    case 1:System.out.print(a+b);
    case 2:System.out.print(a-b);
    case 3:System.out.print(a*b);
    case 4:System.out.print(a/b);
}

       in.close();
    }
}

with the sum I get 100251
division of the norms
calculation 0251

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
antonwx, 2020-10-02
@erzik

You should probably put breeches

public static void main(String[] args) {
      Scanner in = new Scanner(System.in);
      System.out.print("Input a number: ");
      int a = in.nextInt();
      System.out.print("Input a number: ");
      int b= in.nextInt();
  
      System.out.println("Введите действия с числами\n 1.сложить\n 2.вычесть \n 3.Умножить \n 4.Поделить");
      int t=in.nextInt();
      switch (t) {
      case 1:
        System.out.print(a+b);
        break;
      case 2:
        System.out.print(a-b);
        break;
      case 3:
        System.out.print(a*b);
        break;
      case 4:
        System.out.print(a/b);
        break;
      }
    }

System.in, by the way, is not closed

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question