0

So I'm making a Java Util and I am stuck on this part of code.

public void getInput(String i){
    int i = scan.nextInt()
}

Why won't this work?

javaboy
  • 57
  • 1
  • 7

2 Answers2

1

i is already declared as String yet you redeclare i as an int. That can't work!

cmd
  • 11,622
  • 7
  • 51
  • 61
  • What I was trying to do about 3 months ago was use the name of String i to name the int. But, i chnged it around: – javaboy Jan 17 '14 at 16:24
0

You have two variables, which has the same name i but has the different type.

Change it like,

public void getInput(String i){
    int data = scan.nextInt();
}

and the Complier error will be gone.

Mengjun
  • 3,159
  • 1
  • 15
  • 21
  • But I need the String to be identified as i. So if a Dev types getInput(stackoverflow) it should ask for input and store it under int stackoverflow so they can case(stacloverflow) – javaboy Nov 14 '13 at 03:38